<![CDATA[Forum Ubuntu-fr.org / Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?id=1131121 Sun, 23 Dec 2012 17:21:59 +0000 FluxBB <![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11967241#p11967241 Merci smile, mais j'ai pas trop compris à quoi sert la commande hg clone...

pygame semble être installé correctement maintenant smile

Mais quand je lance ce programme depuis Geany:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys, pygame
pygame.init()

size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
  
screen = pygame.display.set_mode(size)
    
ball = pygame.image.load("ball.bmp")
ballrect = ball.get_rect()
    
while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

        ballrect = ballrect.move(speed) 
        if ballrect.left < 0 or ballrect.right > width:
            speed[0] = -speed[0]
        if ballrect.top < 0 or ballrect.bottom > height:
            speed[1] = -speed[1]
   
        screen.fill(black)
        screen.blit(ball, ballrect)
        pygame.display.flip()

j'ai ce message d'érreur:

 File "pygame-exemple.py", line 4, in <module>
 import pygame
ImportError: No module named pygame

Et quand je lance le programme avec la commande: python3 pygame-exemple dans un terminal çà fonctionne...
Comment ça ce fait que çà ne marche depuis Geany???

]]>
Sun, 23 Dec 2012 17:21:59 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11967241#p11967241
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11966561#p11966561 D'après cette page
http://www.pygame.org/wiki/CompileUbunt … ompilation

ceci devrait aller

sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev
 
hg clone https://bitbucket.org/pygame/pygame
 
cd pygame
python3 setup.py build
sudo python3 setup.py install
]]>
Sun, 23 Dec 2012 16:10:09 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11966561#p11966561
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11964321#p11964321 Merci smile

Maintenant, j'ai un autre problème:
J'ai installé pygame par synaptic, et quand j'essaye l'exemple de code suivant:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys, pygame
pygame.init()

size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
  
screen = pygame.display.set_mode(size)
    
ball = pygame.image.load("ball.bmp")
ballrect = ball.get_rect()
    
while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

        ballrect = ballrect.move(speed) 
        if ballrect.left < 0 or ballrect.right > width:
            speed[0] = -speed[0]
        if ballrect.top < 0 or ballrect.bottom > height:
            speed[1] = -speed[1]
   
        screen.fill(black)
        screen.blit(ball, ballrect)
        pygame.display.flip()

Quand je lance le programme j'ai le message d'erreur suivant:

  File "pygame.py", line 3, in <module>
    import sys, pygame
  File "/home/alex/Bureau/python/exercice/pygame.py", line 4, in <module>
    pygame.init()
AttributeError: 'module' object has no attribute 'init'

J'ai lu quelque part que le dépôt python-pygame (1.9.1) qui se trouve dans synaptic est conçu pour tourner sur python2.6...

Moi, j'utilise python3.2 et sur le site officiel je ne trouve pas la version de pygame qui tourne avec cette version de python(http://www.pygame.org/download.shtml).

Quelqu'un pourrais t'il m'indiquer la marche à suivre pour installer pygame pour python3.2?

]]>
Sun, 23 Dec 2012 12:06:07 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11964321#p11964321
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11945181#p11945181
# -*- coding: utf-8 -*-

t1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12]
t2 = ['Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin','Juillet',
        'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre']

# Méthode longue

t3 = []
for i, t in enumerate(t1):
    t3.append(str(t))
    t3.append(t2[i])

ch = ', '.join(t3)

print(ch)

# Méthode simple (ou compliquée selon le point de vue)

ch = ', '.join(['%s, %s' %(str(x), z) for x, z in [y for y in zip(t1, t2)]])

print(ch)

Bon apocalypse Python.

]]>
Fri, 21 Dec 2012 12:05:53 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11945181#p11945181
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11935071#p11935071 oui j'ai trouvé smile

Quelqu'un pourrait me dire comment on se sert du générateur de documentation de geany?
Comment peut on s'assurer que geany lance le script en python3 et non pas dans une ancienne version de python?

J'ai commencé a étudier python(variable, type, boucle, condition, liste, ...) avec l'excellent livre de Gérard Swinnen http://inforef.be/swi/python.htm  et maintenant je commence les fonctions, je trouve vraiment ce langage vraiment facile à apprendre.

J'ai un petit souci avec la fonction print(), par exemple dans le programme suivant:

t1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12]
t2 = ['Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin','Juillet',
 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre']
t3 = []

n = 0
while n < len(t1) :
	t3.append(t1[n])
	t3.append(t2[n])
	n= n+ 1 	
print(t3)

#affiche le résultat:
>>>[1, 'Janvier', 2, 'Fevrier', 3, 'Mars', 4, 'Avril', 5, 'Mai', 6, 'Juin', 7, 'Jui
llet', 8, 'Aout', 9, 'Septembre', 10, 'Octobre', 12, 'Novembre']

,
Je voudrais formater l'affichage du texte à l'écran pour le rendre plus "propre" dans le genre de çà:

>>>1, janvier 2, Fevrier, 3, Mars 4, Avril, ...

Ou afficher les mois de l'année en deux colonnes...

]]>
Thu, 20 Dec 2012 13:56:18 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11935071#p11935071
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11907531#p11907531 Tu ne trouve rien sur ce site?

]]>
Mon, 17 Dec 2012 19:07:57 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11907531#p11907531
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11906741#p11906741 Il y a la doc officielle, même si elle n'est pas en français, c'est je pense la meilleure façon de se renseigner. Il y a même des tutos pour débuter (en anglais aussi).

]]>
Mon, 17 Dec 2012 18:06:15 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11906741#p11906741
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11903291#p11903291 Les liens pour télécharger les exemples de codehttp://python.developpez.com/sources/ sad

Je suis aussi à la recherche d'une documentation sur la bibliothèque standard de python, si possible en Français ...

]]>
Mon, 17 Dec 2012 12:36:01 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11903291#p11903291
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11881671#p11881671 Tu ne trouves pas ton bonheur ici ou ici?

]]>
Sat, 15 Dec 2012 16:28:52 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11881671#p11881671
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11879341#p11879341 Merci smile

Existe t'il des exemples d'applications avec tuto?

]]>
Sat, 15 Dec 2012 11:47:23 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11879341#p11879341
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11870671#p11870671 Sinon, j'ai appris Python avec ça. Le but du tuto est d'être accessible et utile autant aux débutants qu'aux programmeurs expérimentés.

]]>
Fri, 14 Dec 2012 15:49:36 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11870671#p11870671
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11870331#p11870331 Oui c'est de çà que je parlais... smile
Mais quand j'ai écrit mon dernier post, je n'avais dit que mes premières impressions. Maintenant que je parcours ce pdf plus sérieusement, il me semble bien fait, et me convient parfaitement.

]]>
Fri, 14 Dec 2012 15:33:19 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11870331#p11870331
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11866631#p11866631 brital a écrit :

Merci, cette documentation me semble plutôt complète et complexe pour un débutant python smile

Complexe, non je ne pense pas.
Du moins ce n’est pas le but.

Introduction à Python 3 a écrit :

Outre ce cadre universitaire assez réduit, ce cours s’adresse à toute personne désireuse d’apprendre Python en tant que premier langage de programmation.

On parle bien de la même chose (à savoir, ça) ?

]]>
Fri, 14 Dec 2012 10:55:43 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11866631#p11866631
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11866501#p11866501 Merci, cette documentation me semble plutôt complète et complexe pour un débutant python smile

Au fait comment je fais pour exécuter le codepython que je tape dans Geany?

]]>
Fri, 14 Dec 2012 10:49:10 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11866501#p11866501
<![CDATA[Réponse à : Besoin de conseils pour débuter en python]]> http://forum.ubuntu-fr.org/viewtopic.php?pid=11866291#p11866291 Ok, donc en français il y a ça.
Le problème des ressources en français c‘est qu‘elles ne couvrent pas souvent Python 3, c’est un peu con quand même.

]]>
Fri, 14 Dec 2012 10:21:30 +0000 http://forum.ubuntu-fr.org/viewtopic.php?pid=11866291#p11866291