PDA

View Full Version : Help about Python needed please.


rendy
09-02-2002, 01:31 PM
Hi, I'm a newbie in programation, and I'm trying to learn Python, but I don't what programs I must use to be able to "make" Python programs??? Can somebody help me?????
Also, I would like to know if the programs who are "made" with Python are able to be used on Windows and Linux, or just Linux?????????
Thanks a lot for your help :) .
Bye, and see you later.

rendy

Strike
09-02-2002, 01:45 PM
Python programs aren't really compiled (in the traditional "code to binary executable" sense), so you just need the interpreter. Write your python program and then run python myprogram.py

inkedmn
09-02-2002, 01:51 PM
www.python.org :)

rendy
09-02-2002, 05:39 PM
Originally posted by Strike
Python programs aren't really compiled (in the traditional "code to binary executable" sense), so you just need the interpreter. Write your python program and then run python myprogram.py
I don't really see what you mean. I've downloaded "Python 2.2.1" on www.python.org, and a book for learning Python (french book), and they seemed to speak about a executable file... Can you explain me again what you said.
Also, I don't understand what you said : "python myprogram.py". Do I have to do this with what I've downloaded on www.python.org ("Python 2.2.1"), can you explain me please ???
Thanks a lot for your help :) .
Bye, and see you later.

rendy

GnuVince
09-02-2002, 05:45 PM
rendy: are you french? Or better yet, Québecois?

inkedmn
09-02-2002, 07:21 PM
"python myprogram.py"

you're executing the python intepreter ("python") against your python file ("myprogram.py").

here's an example:

this is a python script called "nums.py":


#!/usr/bin/env python

i = 0
while i <= 10:
print i,
i += 1


now, here is what it looks like when you run it (including the command to run it):


C:\brett>python nums.py
0 1 2 3 4 5 6 7 8 9 10


make sense?

rendy
09-03-2002, 09:07 AM
Originally posted by inkedmn
"python myprogram.py"

you're executing the python intepreter ("python") against your python file ("myprogram.py").

here's an example:

this is a python script called "nums.py":


#!/usr/bin/env python

i = 0
while i <= 10:
print i,
i += 1


now, here is what it looks like when you run it (including the command to run it):


C:\brett>python nums.py
0 1 2 3 4 5 6 7 8 9 10


make sense?
Ok, thanks a lot for your help :). Its more clear for me now :) .
Originally posted by GnuVince
rendy: are you french? Or better yet, Québecois?
Yes, I'm french :) . And you????
Thanks a lot for your help :).
Bye, and see you later.

rendy

GnuVince
09-03-2002, 01:18 PM
rendy: Oui, je viens du Québec et je parle français. Si jamais il y a des explications en anglais que tu ne comprends pas, tu peux toujours venir me voir, ça va me faire plaisir de te donner un coup de pouce

rendy
09-04-2002, 11:17 AM
Ok, merci beaucoup, c'est très sympa de ta part :).
Tu sais où je peux trouver des tutorials sur le Python pour gros débutant en français :rolleyes: ???
Merci beaucoup d'avance pour ton aide.
Bye, et a plus.

rendy

kmj
09-04-2002, 11:48 AM
(translated by babelfish)
Gnuvince said: "rendy: Yes, I come from Quebec and I speak French. If ever there are explanations in English whom you do not include/understand, you can always come to see me, that will please to me to give you a blow of inch "

then rendy said: "Ok, thank you very much, they is very sympathetic of your share. You know where I can find tutorials on the Python for large French beginner??? Thank you very much in advance for your assistance. Bye, and has more. "


Lucky for you, there are alot of french resources! (apparently) ...

NonEnglish Python Resources List from Python.org (http://www.python.org/doc/NonEnglish.html)

French has quite a few; second only to German.

rendy
09-05-2002, 01:40 PM
Ok, thanks a lot :D.

rendy
09-07-2002, 01:35 PM
GnuVince: desolé, mais je vais parler en anglais pour que tout le monde puisse comprendre, sinon c'est pas très sympa pour les autres :rolleyes: ;) .

I've downloaded a *.pdf file about learning Python(in french), and so I'm reading it, and doing the small exercices, and I have some problems, so I would like to know if you can help me to fix them (sorry but some parts of the "source code" that I've written are in french).

I typed every thing like they said in the *.pdf file, and I had this:
http://www.villagephotos.com/viewpubimage.asp?id_=662850
So, I changed "négatif" to "negatif",then I was able to continu to type, and then, I got this:
http://www.villagephotos.com/viewpubimage.asp?id_=662851
Is that all normal?? Is there a difference between an "é" and an "e", does Python doesn't accept the "é"????

Then, I had another problem, I typed like they said in the *.pdf file, and I got this:
http://www.villagephotos.com/viewpubimage.asp?id_=662852
But then, when I pressed "Enter", I got this:
http://www.villagephotos.com/viewpubimage.asp?id_=662853
Why do I get this??? Is that normal?? Did I made a mistake?? Which one??? What must I do???
Please help me.
Thanks a lot for all the help that you can give :D.
Bye, and see you later.

rendy

Strike
09-07-2002, 02:00 PM
That last one makes no sense to me - why would you have a string on a line by itself? Are you sure that's exactly what's in the PDF? It shouldn't work.

kmj
09-07-2002, 02:24 PM
GnuVince: desolé, but I will speak in English so that everyone can include/understand, if not they is not very sympathetic for the others.


gracias amigo! :)

strike: it's not a string on a line by itself; barely visible under the highlighting is the word 'print'..
so it's a seperate print statement, outside of any blocks.

Now, rendy: you may want to paste that code here, exactly as it is typed, inside code UBB tags. Is that last line indented at all? It looks like it is, and it shouldn't be. Idle is a little weird because the prompt makes the first line to look like it's indented, when it really isn't. I think the syntax error you're getting is due to improper indentation. Remember that indentation is one of the most important things in a python program.

rendy
09-07-2002, 08:36 PM
Originally posted by kmj


gracias amigo! :)

Now, rendy: you may want to paste that code here, exactly as it is typed, inside code UBB tags.
You're welcome :D.
I'll past the code in my next post, because right now its late where I live, and so, I don't really want to play with Python at this time ;) .
Whats "code UBB tags":wtf: ???
Originally posted by Strike
That last one makes no sense to me - why would you have a string on a line by itself? Are you sure that's exactly what's in the PDF? It shouldn't work.
Scuse me, but I don't understand what you're saying (I'm not very good in english...sorry)??!
Thanks a lot for your help :D.
Bye, and see you later.

rendy

inkedmn
09-07-2002, 08:47 PM
re: code tags...

if you want to post some code so it looks nice and formatted, just paste it between these two tags:

[ code ]

[ /code ]

(but remove the spaces)

Strike
09-07-2002, 10:32 PM
kmj: gracias, that's something I never would have found

rendy: you need to realize that how far you indent things is CRUCIAL in python, and is part of the syntax. Indenting things too much or not enough is a syntax error

rendy
09-10-2002, 02:48 PM
Ok, here is a past of all the things I typed in the "Python GUI":

Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> embranchement == "vertebres":

SyntaxError: invalid syntax
>>> embranchement == "vertebres"
Traceback (most recent call last):
File "<pyshell#1>", line 1, in ?
embranchement == "vertebres"
NameError: name 'embranchement' is not defined
>>> embranchement = vertebres
Traceback (most recent call last):
File "<pyshell#2>", line 1, in ?
embranchement = vertebres
NameError: name 'vertebres' is not defined
>>> embranchement = "vertebres"
>>> classe = "mammiferes"
>>> ordre = "carnivores"
>>> famille = "felins"
>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"


c'est peut-etre un chat
>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"
print "c'est en tous cas un mammifere"
elif classe == 'oiseaux':
print "c'est peut-etre un canari"
print "la classification des animaux est complexe"

IndentationError: unindent does not match any outer indentation level (line 9)
>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"
print "c'est en tous cas un mammifere"
elif classe == 'oiseaux':
print "c'est peut-etre un canari"
print "la classification des animaux est complexe"

IndentationError: unindent does not match any outer indentation level (line 9)
>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"
print "c'est en tous cas un mammifere"
elif classe == "oiseaux":
print "c'est peut-etre un canari"
print "la classification des animaux est complexe"

IndentationError: unindent does not match any outer indentation level (line 9)
>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"
print "c'est en tous cas un mammifere"
elif classe == 'oiseaux':
print "c'est peut-etre un canari"
print "la classification des animaux est complexe"

IndentationError: unindent does not match any outer indentation level (line 9)
>>>
I'll attach also a *.txt file with the source code to the post, if there a kind of problem :rolleyes: :D. So?? Can you help me to see whats the problem???
Also, here is whats in the *.pdf I'm learning with, for the exercice(sorry...its in french):
http://www.villagephotos.com/viewpubimage.asp?id_=678672. So?? Can you help me to see whats the problem???
Also, I wanted to ask you, is there a difference between "é" and "e" in Python??? Is it a mistake to write an "é"??? Because I tried, and I had some error messages, why????
Thanks a lot for your help :D.
Bye, and see you later.

rendy

kmj
09-10-2002, 03:09 PM
okay, regarding the different types of 'e', I can't help, since I've no experience in that arena. Perhaps gnuvince knows?

Now, the reason you're getting errors: (I think)
Was that code meant to be written in the interpreter? It seems to be a fragment of a program.

When you look at the pdf file, you'll see that the first line and the last line have the same indentation; in your code, they do not. (they look like they do, because of idle's prompt pushing in the first line). The last line should have no indentation. This is what Strike and I were trying to stress earlier.

Now, even if the first line has no indentation, your code still won't work right in Idle. This is because the code presented to you constists of multiple statements, so Idle get's confused. (I don't know if it's Idle's fault, or the python interpreter.) What I'm saying here is this:

(a) you code should look like this

>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"
print "c'est en tous cas un mammifere"
elif classe == 'oiseaux':
print "c'est peut-etre un canari"
print "la classification des animaux est complexe"

That is the equivilent of what is in the pdf file. (notice the last line.)


(b) Even that, when pasted into idle doesn't work, but the code isn't actually wrong. It must be how idle handles multiple statements.. If you take the above lines and put them in a file after some lines assigning values to those variables (let's call it "myfile.py"), then run at the command line "python myfile.py", then it should work fine.

I hope I've cleared things up for you a little.

GnuVince
09-10-2002, 05:42 PM
>>> jérôme = "Jérôme"
>>> print jérôme
Jérôme
>>>


It seems to work fine. Of course, I absolutely advise you not to use accented characters in your code!

kmj
09-10-2002, 09:32 PM
yeah, some of us stupid americans don't even know how to make accented character!

~lart me

:)

GnuVince
09-10-2002, 11:11 PM
kmj: you get a real keymap layout (canadian french!)

inkedmn
09-10-2002, 11:12 PM
bah...

/me has no need for accented characters, he's a stupid american!!!

~praise ignorance ;)

rendy
09-11-2002, 03:48 AM
Originally posted by GnuVince

>>> jérôme = "Jérôme"
>>> print jérôme
Jérôme
>>>


It seems to work fine. Of course, I absolutely advise you not to use accented characters in your code!
What???????????????? I've downloaded Pyhton from www.python.org, the last version(2.2), is that normal???
Originally posted by kmj
okay, regarding the different types of 'e', I can't help, since I've no experience in that arena. Perhaps gnuvince knows?

Now, the reason you're getting errors: (I think)
Was that code meant to be written in the interpreter? It seems to be a fragment of a program.

When you look at the pdf file, you'll see that the first line and the last line have the same indentation; in your code, they do not. (they look like they do, because of idle's prompt pushing in the first line). The last line should have no indentation. This is what Strike and I were trying to stress earlier.

Now, even if the first line has no indentation, your code still won't work right in Idle. This is because the code presented to you constists of multiple statements, so Idle get's confused. (I don't know if it's Idle's fault, or the python interpreter.) What I'm saying here is this:

(a) you code should look like this

>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"
print "c'est en tous cas un mammifere"
elif classe == 'oiseaux':
print "c'est peut-etre un canari"
print "la classification des animaux est complexe"

That is the equivilent of what is in the pdf file. (notice the last line.)


(b) Even that, when pasted into idle doesn't work, but the code isn't actually wrong. It must be how idle handles multiple statements.. If you take the above lines and put them in a file after some lines assigning values to those variables (let's call it "myfile.py"), then run at the command line "python myfile.py", then it should work fine.

I hope I've cleared things up for you a little.
Yes, now its seems to be a little bit more clear for me :D. But why do I have do past the code un a *.py file to make it work??? It should work in the "Pyhton GUI"(IDLE I think :rolleyes:), no??? Is it a bug???? Please help :D.
I'll try to past the code in a *.py file to see what happens :D.
Thanks a lot for your help :D.
Bye, and see you later.

rendy
P.s.: I wont use "é" or other caracters like this one in my future source codes, don't worry :D. I'm just curious of understanding that problem :D.
Bye.

GnuVince
09-11-2002, 07:12 AM
rendy: I'd bet it is due to the platform. I use Linux, you use Windows. I'm quite certain that this is the reason.

kmj
09-11-2002, 09:50 AM
rendy: the GUI works fine in most cases, but when you past code into it; seems to get confuse. For example, if you copy and past


print 'hello'
print 'goodbye'


It will only print hello.. if all your code is one big if block, or one function definition, it seems to work fine. Remeber, the interactive console is meant to handle one command at a time, and by giving it multiple unrelated statements, you're not doing that.

rendy
09-11-2002, 11:21 AM
Ok, thanks a lot for all your help, and all those tips :D.
I have another question :D :
I have this code:

>>> if embranchement == "vertebres":
if classe == "mammiferes":
if ordre == "carnivores":
if famille == "felins":
print "c'est peut-etre un chat"
print "c'est en tous cas un mammifere"
elif classe == 'oiseaux':
print "c'est peut-etre un canari"
print "la classification des animaux est complexe"

Notice the part: elif == 'oiseaux':, is there a difference between 'oiseaux' and "oiseaux" :wtf: ??? If yes, which one :wtf: ??
Thanks a lot for your help :D.
Bye, and see you later.

rendy

kmj
09-11-2002, 11:43 AM
no there is no difference... 'string' and "string" do the same thing; it's just easier to use double quotes if your string contains a single quote: "rendy's post", or to use single quotes if your string contains double quotes: 'and I was like "you go girl".' Otherwise, you'd have to use a backslash to show that you weren't ending the string: " he said \"hello\"." or 'she\'s a hottie.'; which makes the string ugly to look at.

rendy
09-13-2002, 03:44 AM
Originally posted by kmj
no there is no difference... 'string' and "string" do the same thing; it's just easier to use double quotes if your string contains a single quote: "rendy's post", or to use single quotes if your string contains double quotes: 'and I was like "you go girl".' Otherwise, you'd have to use a backslash to show that you weren't ending the string: " he said \"hello\"." or 'she\'s a hottie.'; which makes the string ugly to look at.
Scuse me ... but I don't understand what you said :(.
Can you rexplain please????
Thanks a lot for your help :D.
Bye, and see you later.

rendy

GnuVince
09-13-2002, 08:05 AM
Il n'y a pas de différence entre 'chaîne de caractères' et "chaîne de caractères". Par contre, c'est plus esthétique d'utiliser les guillemets quand il y a des apostrophes dans la chaîne, et d'utiliser des apostrophes pour délimiter la chaîne quand elle contient des guillemets:

"J'ai une apostrophe dans ma phrase"
'Je lui ai dit: "Voici une chaîne avec des guillemets"'


Autrement, il faut faire un "escape" des caractères:

'J\\'ai une apostrophe'
"\"Guillemets\""


C'est moins esthétique et plus difficile à lire. Choisit en conséquence. S'il n'y a pas de guillemets ou d'apostrophes dans la chaîne, c'est libre à toi, tant que tu restes constant dans tes utilisations. Personnellement je préfère utiliser les guillemets/apostrophes de la même façon qu'en C ou en O'Caml: apostrophes pour un seul caractère et des guillemets pour une chaîne de 2 caractères et plus.

rendy
09-13-2002, 02:51 PM
Originally posted by GnuVince

Autrement, il faut faire un "escape" des caractères:

'J\'ai une apostrophe'
"\"Guillemets\""


C'est moins esthétique et plus difficile à lire. Choisit en conséquence. S'il n'y a pas de guillemets ou d'apostrophes dans la chaîne, c'est libre à toi, tant que tu restes constant dans tes utilisations. Personnellement je préfère utiliser les guillemets/apostrophes de la même façon qu'en C ou en O'Caml: apostrophes pour un seul caractère et des guillemets pour une chaîne de 2 caractères et plus.
Ok, j'ai compris le début, mais l'histoire du "escape" de caractères non :( ... Desoler de t'embeter avec tout ça, mais est-ce-que tu peux me rexpliquer le truc du "escape" de caractères????
Sinon, j'ai piger tous le reste :D.
I'm really sorry for all the persons who don't speak french, if you want, I can translate for you. I hope that you don't take it bad.
Thanks a lot for your help GnuVince and the other :D :D.
Bye, and see you later.

rendy

GnuVince
09-13-2002, 05:49 PM
rendy: pour imprimer une apostrophe, ceci ne fonctionne pas:

print '''


car l'interpréteur voit la seconde et croit qu'il vient de trouver la fin de la chaîne. Mais c'est faux. Donc, pour qu'il imprime, on ajoute un back-slash devant le caractère:

print '\\''


On appelle cette technique, escaping.

Strike
09-13-2002, 06:58 PM
In GnuVince's second code block, that should be:

'J\\'ai une apostrophe'

Funny how you do the example code block to demonstrating "escapirng" characters and then miss one :P

----edit----
Hey, what the sh__? There's another bug, if you put \' into a code block it seems to interpret that as an escaped apostrophe. Apologies to GnuVince.

GnuVince
09-13-2002, 08:05 PM
Strike: yeah, I saw it in my second example.

rendy
09-14-2002, 11:11 AM
Originally posted by Strike
In GnuVince's second code block, that should be:

'J\\'ai une apostrophe'

Funny how you do the example code block to demonstrating "escapirng" characters and then miss one :P

----edit----
Hey, what the sh__? There's another bug, if you put \' into a code block it seems to interpret that as an escaped apostrophe. Apologies to GnuVince.
Sorry, I didn't understand, what you said in your "----edit---- section". Can you explain that to me???
Originally posted by GnuVince
rendy: pour imprimer une apostrophe, ceci ne fonctionne pas:

print '''


car l'interpréteur voit la seconde et croit qu'il vient de trouver la fin de la chaîne. Mais c'est faux. Donc, pour qu'il imprime, on ajoute un back-slash devant le caractère:

print '\\''


On appelle cette technique, escaping.
Ok, mais tu as dis ça dans un de tes posts :rolleyes: :
Originally posted by GnuVince

Autrement, il faut faire un "escape" des caractères:

'J\'ai une apostrophe'
"\"Guillemets\""


Donc, si je fais comme tu as dis, ça devrait plutôt être ça:
"\"Guillemets"\"Non??? Ou je me trompe???
Merci d'avance pour ton aide :D.
Thanks a lot for your help :D.
Bye, and see you later.

rendy

GnuVince
09-14-2002, 02:08 PM
rendy, il y a un bug dans VBulletin, qui fait que dans mon premier exemple le back-slsh n'apparaissait pas.

Mais si tu veux comprendre, ouvre l'interpréteur et essaye!

rendy
09-14-2002, 06:13 PM
Ok, j'ai tout compris :D :D.
Toutes mes excuses si je t'ai offenser.
j'ai essayer de taper les trucs en question dans IDLE(Python GUI), et c'est bon, j'ai compris :D.
Otherwise, Strike: now I understand what you said about the bug :D. It's in VBulletin, that there is this bug, right??
Thanks again for your help :D.
Bye, and see you later.

rendy

Strike
09-14-2002, 06:44 PM
rendy: it seems to have been fixed now :)

hats off to the cf.net crew :P

rendy
09-15-2002, 09:20 PM
Originally posted by Strike
rendy: it seems to have been fixed now :)

hats off to the cf.net crew :P
Yeah :D.