Cheat sheet

K

kyosohma

(e-mail address removed) ha scritto:


Thanks :)
I'll read them to improve my python knowledge, but I prefere to have a
very small cheat sheet to keep near me.

Yeah...they can be handy. I like that Quick Reference card, but it is
a little unwieldy.

Mike
 
C

Carl Banks

I wrote a little cheat sheet for this wonderful language, but because of
my still little experience with it, I would like to have a feedback
Could you have a look at it and tell me what do you think about, please?

http://greyfox.imente.org/index.php?id=73

Nice work.

Only questionable thing I could see is listing dict.has_key(): I'm not
sure of it's officially deprecated but the recommended practice these
days is to to use "key in dict_obj".

Also, consider adding a line or two about the set objects. (It's
probably at least better than listing internal objects.)


Carl Banks
 
R

Riccardo T.

Carl Banks ha scritto:
Nice work.

I'm very glad you liked it :)
Only questionable thing I could see is listing dict.has_key(): I'm not
sure of it's officially deprecated but the recommended practice these
days is to to use "key in dict_obj".

I listed it because of help(dict.has_key) doesn't show any warning about
that. However, if "in" works as well, I'll remove it very soon.
Also, consider adding a line or two about the set objects. (It's
probably at least better than listing internal objects.)

I forgot it... thank you very much. I hope I'll find some more space to
write on.
 
S

Scott David Daniels

Riccardo said:
I wrote a little cheat sheet for this wonderful language, but because of
my still little experience with it, I would like to have a feedback
Could you have a look at it and tell me what do you think about, please?

http://greyfox.imente.org/index.php?id=73

[in the .png]
> ...
> Callable types
> ...
> User-definet methods

I personally prefer "User-defined methods"
> ...
> Class instances
I'd try:
Class instances with a __call__ method.
> ...
> Classes
> Classes Instances

This probably wants to be
Class Instances

"file" objects are generally supposed to be built with the
open function, not instantiated as shown.
Also note iterating on a file gets the lines.

Do you know about seq[i:] and seq[::-1]?

--Scott David Daniels
(e-mail address removed)
 
R

Riccardo T.

Scott David Daniels ha scritto:
[in the .png]
...
Callable types
...
User-definet methods

I personally prefer "User-defined methods"

That's a typo, thank you.

I'd try:
Class instances with a __call__ method.

Yes, it's more clear now.

This probably wants to be
Class Instances

Whoops, I'm sorry :)

"file" objects are generally supposed to be built with the
open function, not instantiated as shown.

Since open() is just an alias for file(), changing the name should be
enough, right?

Also note iterating on a file gets the lines.

What do you think about adding a line like this to the examples?

for line in open("filename","r"): pass #iterate over lines

Do you know about seq[i:] and seq[::-1]?

Yes I know. I'll try to add them (together with seq[:] and seq[:j]).



Thank you very much indeed :)
 
M

Michele Simionato

Since open() is just an alias for file(), changing the name should be
enough, right?

It depends on the Python version:

Python 2.4.4 (#2, Oct 4 2007, 22:02:31)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.True

Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.False

Nowadays file is no more an alias for open.

Michele Simionato
 
C

c james

Riccardo said:
I wrote a little cheat sheet for this wonderful language, but because of
my still little experience with it, I would like to have a feedback
Could you have a look at it and tell me what do you think about, please?

http://greyfox.imente.org/index.php?id=73

On the svg version, as viewed on firefox, the sections "Simple
statements", "Definations" and "Comments"; there appears to be a problem
with text wrapping.
 
R

Riccardo T.

c james ha scritto:
On the svg version, as viewed on firefox, the sections "Simple
statements", "Definations" and "Comments"; there appears to be a problem
with text wrapping.

I see, it has already been signaled by mail. I'm not sure about how to
fix that, I'll have to ask someone who knows Inkscape. Thanks.

I'm working at the next release now, it should be available quite soon.
 
S

Scott David Daniels

Riccardo said:
Scott David Daniels ha scritto:
[in the .png]
...
Callable types
...
User-definet methods
I personally prefer "User-defined methods"

That's a typo, thank you.

Hope I didn't offend (I was simply trying to be cute).
Some from a bit further along. I know I didn't say so
explicitly, but I don't spend much effort in pointing out
errors in useless things.

---
lambda is an expression, not a statement.

Might include callable-invocation in operators?
divmod, pow, int, long, float are in __builtin__, not math.
Note pow(base, exponent[, modulus] is good for crypto stuff.

Useful modules to read actually should include __builtin__,
os, and os.path -- maybe include os.walk and os.path.join.

--Scott David Daniels
(e-mail address removed)
 
R

Riccardo T.

Scott David Daniels ha scritto:
Riccardo said:
Scott David Daniels ha scritto:
[in the .png]
...
Callable types
...
User-definet methods
I personally prefer "User-defined methods"

That's a typo, thank you.

Hope I didn't offend (I was simply trying to be cute).
Some from a bit further along. I know I didn't say so
explicitly, but I don't spend much effort in pointing out
errors in useless things.

No, you did't :)


I'll remove that from the expression list.

Might include callable-invocation in operators?
divmod, pow, int, long, float are in __builtin__, not math.

Yes I know, it has already been signaled by mail. They will be removed
in the next version, except pow (the version with two arguments that is
in my list belongs to math, while pow(b,e,m) is from __builtin__).

Note pow(base, exponent[, modulus] is good for crypto stuff.
Useful modules to read actually should include __builtin__,
os, and os.path -- maybe include os.walk and os.path.join.

Maybe I'll add __builtin__ and os in place of the type hierarchy, but
I'm not sure about that. However, not in the next release. What do you
think about?
 
S

Scott David Daniels

Riccardo said:
Scott David Daniels ha scritto:
Riccardo said:
Scott David Daniels ha scritto:
[in the .png]
...
Callable types
...
User-definet methods
I personally prefer "User-defined methods"
That's a typo, thank you.
Hope I didn't offend (I was simply trying to be cute).
Some from a bit further along. I know I didn't say so
explicitly, but I don't spend much effort in pointing out
errors in useless things.

No, you did't :)


I'll remove that from the expression list.

Might include callable-invocation in operators?
divmod, pow, int, long, float are in __builtin__, not math.

Yes I know, it has already been signaled by mail. They will be removed
in the next version, except pow (the version with two arguments that is
in my list belongs to math, while pow(b,e,m) is from __builtin__).

Note pow(base, exponent[, modulus] is good for crypto stuff.
Useful modules to read actually should include __builtin__,
os, and os.path -- maybe include os.walk and os.path.join.

Maybe I'll add __builtin__ and os in place of the type hierarchy, but
I'm not sure about that. However, not in the next release. What do you
think about?

How about:
top line w/ __builtin__, os, os.path (and no contents -- inspire
further reading).

On left for numbers:

Numbers
long (big integers e.g. 9876543210L)
int (plain integers e.g. 123)
bool (booleans 0==False, 1==True)
float (floating point)
complex (e.g. 9j)
Similarly str, unicode, tuple, list [that is, the precise type name]

int (plain integers like 12)
 
A

Alaric

Riccardo said:
I wrote a little cheat sheet for this wonderful language, but because of
my still little experience with it, I would like to have a feedback
Could you have a look at it and tell me what do you think about, please?

http://greyfox.imente.org/index.php?id=73

Nicely done! I would suggest you put your website address on it and a revision
number so that as it gains use on te web, people can find the "latest"
version.
 
R

Riccardo T.

Alaric ha scritto:
Nicely done! I would suggest you put your website address on it and a revision
number so that as it gains use on te web, people can find the "latest"
version.

That's a good idea, thank you :)
 
Z

ZeD

Michele said:
Python 2.4.4 (#2, Oct 4 2007, 22:02:31)
True

Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
False

Nowadays file is no more an alias for open.

curious... maybe it's me, but I can't find a "What's New in Python" where
this is said... also, in 2.6 docs (and also in 2.5) remains this footer:

http://docs.python.org/dev/library/stdtypes.html#id14
http://www.python.org/doc/2.5/lib/bltin-file-objects.html#foot4449

file() is new in Python 2.2. The older built-in open() is an alias for
file().
 
R

Riccardo T.

Scott David Daniels ha scritto:
How about:
top line w/ __builtin__, os, os.path (and no contents -- inspire
further reading).

I'm sorry, but what do you mean with "top line w/"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top