What AugStore and AugLoad AST nodes are?
Dear all, I'm experimenting with new ast module. I'd like to have pieces of code that can generate AugLoad and AugStore AST nodes. Indeed, I actually do not know what they correspond to. Thanks for any help! Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: What AugStore and AugLoad AST nodes are?
> They aren't used by the current implementation. OK, thanks! Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Safe eval of insecure strings containing Python data structures?
> I would like to parse arbitrary insecure text string containing nested > Python data structures in eval-compatible form: Python 2.6 has ast.literal_eval to do exactly this. It handle lists, tuples, dict, numbers, strings, bool and None, with arbitrary nesting. Cheers, Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Pathological regular expression
> To my mind, this is a bug in the RE engine. Is there any reason to not > treat it as a bug? It's not a bug, it's a feature! ;-) Indeed, in order to handle constructs like (?P=name), RE engines have to use inefficient algorithms. In my opinion, this is not the problem of using a pathological regular expression, but rather a problem of the RE engine that is not optimized to use the faster approach when possible. This is well known problem very well explained on: http://swtch.com/~rsc/regexp/regexp1.html Cheers, Franck -- http://mail.python.org/mailman/listinfo/python-list
About the grammar
Dear all, I'm wondering why in Python's grammar, keyword arguments are specified as: argument: ... | test '=' test I would have expected something like argument: ... | NAME '=' test Indeed, I cannot imagine a case where the keyword is something else than an identifier. Moreover, in the Python language reference (see http://docs.python.org/reference/expressions.html#grammar-token-keyword_item) one can read: keyword_item ::= identifier "=" expression which is what I was expecting. Does any one knows why the grammar is so coded? Any intuition? Thanks in advance! Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: About the grammar
Thank you for this very clear (and quick) explanation! :-) Cheers, Franck On 19 avr, 08:58, "Martin v. Loewis" wrote: > # The reason that keywords are test nodes instead of NAME is that using > # NAME results in an ambiguity. ast.c makes sure it's a NAME. > argument: test [comp_for] | test '=' test [...] -- http://mail.python.org/mailman/listinfo/python-list
Re: About the grammar
> > argument: ... | test '=' test > Where are you finding that? This comes from Python-2.6/Grammar/Grammar in the source distribution. > This tells you that keyword arguments cannot have keywords that aren't > identifiers: > > >>> sum(1=2) > > File "", line 1 > SyntaxError: keyword can't be an expression Sure! So my surprise. But Martin did provide a very good explanation that this form in the grammar actually allows to avoid an ambiguity. Cheers, Franck -- http://mail.python.org/mailman/listinfo/python-list
Python toplevel in a Web page
Hello, I wonder if I can find some source code example of a Python 3 toplevel box in a Web page. Something simple, no mySQL, no Django hammer, etc. Just the basics of the technology to get the content of a small text editor in which the user writes some Python script, to be analyzed (eval'ed) then whose result is to be written in another text box. Simple, pythonistic. Thanks for the pointer, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda in list comprehension acting funny
In article , Daniel Fetchinson wrote: > > funcs = [ lambda x: x**i for i in range( 5 ) ] > > print funcs[0]( 2 ) > > print funcs[1]( 2 ) > > print funcs[2]( 2 ) > > > > This gives me > > > > 16 > > 16 > > 16 > > > > When I was excepting > > > > 1 > > 2 > > 4 > > > > Does anyone know why? In Python 3.x : funcs = [lambda x: x**i for i in range(5)] list(map(lambda f: f(2),funcs)) --> [16, 16, 16, 16, 16] Ooops, cool semantics :-) In Racket Scheme (http://racket-lang.org), they seem to know lambdas : #lang racket ;;; quick and dirty list comprehension syntax as a macro, for fun : (define-syntax-rule (list-of expr for x in L) (map (lambda (x) expr) L)) (list-of (sqr x) for x in (range 5)) --> (0 1 4 9 16) (define funcs (list-of (lambda (x) (expt x i)) for i in (range 5))) (map (lambda (f) (f 2)) funcs) --> (1 2 4 8 16) franck -- http://mail.python.org/mailman/listinfo/python-list
when an iterable object is exhausted or not
Two similar iterable objects but with a different behavior : $$$ i = range(2,5) $$$ for x in i : print(x,end=' ') 2 3 4 $$$ for x in i : print(x,end=' ')# i is not exhausted 2 3 4 - Compare with : $$$ i = filter(lambda c : c.isdigit(), 'a1b2c3') $$$ for x in i : print(x,end=' ') 1 2 3 $$$ for x in i : print(x,end=' ')# i is exhausted $$$ IMHO, this should not happen in Py3k. What is the rationale of this (bad ?) design, which forces the programmer to memorize which one is exhaustable and which one is not ?... franck -- http://mail.python.org/mailman/listinfo/python-list
How to program test(expr) ?
Hi !
I use Python 3.2.3 + Idle.
Is it possible to program test(e) which takes
an expression e and whose execution produces
at the toplevel an echo of e and the effects
and result of its evaluation ?
# file foo.py
def foo(x) :
print('x =',x)
return x+1
test(foo(5))
# RUN !
# produces at the toplevel :
? foo(5)
x = 5
--> 6
I know I could put the expression e within a string, but
is it possible to avoid the string, like a Lisp macro ?
Thanks.
franck
--
http://mail.python.org/mailman/listinfo/python-list
is implemented with id ?
Hi ! a is b <==> id(a) == id(b) in builtin classes. Is that true ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
Thanks to all, but : - I should have said that I work with Python 3. Does that matter ? - May I reformulate the queston : "a is b" and "id(a) == id(b)" both mean : "a et b share the same physical address". Is that True ? Thanks, franck In article , Benjamin Kaplan wrote: > On Tue, Sep 4, 2012 at 11:30 PM, Franck Ditter wrote: > > Hi ! > > a is b <==> id(a) == id(b) in builtin classes. > > Is that true ? > > Thanks, > > > > franck > > No. It is true that if a is b then id(a) == id(b) but the reverse is > not necessarily true. id is only guaranteed to be unique among objects > alive at the same time. If objects are discarded, their ids may be > reused even though the objects are not the same. -- http://mail.python.org/mailman/listinfo/python-list
sum works in sequences (Python 3)
Hello,
I wonder why sum does not work on the string sequence in Python 3 :
>>> sum((8,5,9,3))
25
>>> sum([5,8,3,9,2])
27
>>> sum('rtarze')
TypeError: unsupported operand type(s) for +: 'int' and 'str'
I naively thought that sum('abc') would expand to 'a'+'b'+'c'
And the error message is somewhat cryptic...
franck
--
http://mail.python.org/mailman/listinfo/python-list
Reading a file in IDLE 3 on Mac-Lion
Hello, I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). It runs fine and creates the disk file, visible with TextWrangler or another. But I can't open it with IDLE (its name is greyed). IDLE is supposed to read utf-8 files, no ? This works on Windows-7. Thanks for the tip, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading a file in IDLE 3 on Mac-Lion
In article <[email protected]>, Hans Mulder wrote: > On 21/09/12 16:29:55, Franck Ditter wrote: > > I create a text file utf-8 encoded in Python 3 with IDLE (Mac Lion). > > It runs fine and creates the disk file, visible with > > TextWrangler or another. > > But I can't open it with IDLE (its name is greyed). > > IDLE is supposed to read utf-8 files, no ? > > This works on Windows-7. > > There's a little pop-menu below the list of files. > > It allows you to choose which kind of files you want to open. > By default, it is set to "Python files", which greys out all > files, except those with a '.py' or '.pyw' extension. > Setting it to "Text files" should help, or else try "All files". > > Hope this helps > > -- HansM Alas this pop-up menu is for Windows only, I don't find it on MacOS-X. My files are xxx.dat files and not visible, even text only (numeric data). This can be filed as something to do ! Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
print or write on a text file ?
Hi ! Here is Python 3.3 Is it better in any way to use print(x,x,x,file='out') or out.write(x) ? Any reason to prefer any of them ? There should be a printlines, like readlines ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
question on log as an instance method
Hi ! Here is Python 3.2.3, MacOSX-Lion Question : I may consider + as an hidden instance method , as 1+2 is equivalent to (1).__add__(2) ? I also consider __abs__ as an instance method : >>> (-2).__abs__() 2 Question 1 : could the parser cope with the mandatory space in 1 .__add__(2) ? Question 2 : After importing math, why can't I consider log as an instance method, after all ? >>> (4).__log__() AttributeError: 'float' object has no attribute '__log__' Thanks for your answers. franck -- http://mail.python.org/mailman/listinfo/python-list
getting the state of an object
Hi ! Another question. When writing a class, I have often to destructure the state of an object as in : def foo(self) : (a,b,c,d) = (self.a,self.b,self.c,self.d) ... big code with a,b,c,d ... So I use the following method : def state(self) : return (self.a,self.b,self.c,self.d) so as to write : def foo(self) : (a,b,c,d) = self.state() ... big code with a,b,c,d ... This is probably not the best Python way to code, is it ? Is there a simple way to get the *ordered* list of instance variables as given in the parameter list of __init__ ? __dict__ gives it but not in order... Thanks a lot, franck -- http://mail.python.org/mailman/listinfo/python-list
Problem with Unicode char in Python 3.3.0
Hi ! I work on MacOS-X Lion and IDLE/Python 3.3.0 I can't get the treble key (U1D11E) ! >>> "\U1D11E" SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-6: end of string in escape sequence How can I display musical keys ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with Unicode char in Python 3.3.0
In article ,
marduk wrote:
> On Sun, Jan 6, 2013, at 11:43 AM, Franck Ditter wrote:
> > Hi !
> > I work on MacOS-X Lion and IDLE/Python 3.3.0
> > I can't get the treble key (U1D11E) !
> >
> > >>> "\U1D11E"
> > SyntaxError: (unicode error) 'unicodeescape' codec can't
> > decode bytes in position 0-6: end of string in escape sequence
> >
>
> You probably meant:
>
> >>> '\U0001d11e'
>
>
> For that synax you must use either '\u' or '\U' (i.e.
> specify either 4 or 8 hex digits).
>
> http://docs.python.org/2/howto/unicode#unicode-literals-in-python-source-code
<<< print('\U0001d11e')
Traceback (most recent call last):
File "", line 1, in
print('\U0001d11e')
UnicodeEncodeError: 'UCS-2' codec can't encode character '\U0001d11e'
in position 0: Non-BMP character not supported in Tk
--
http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python training "text movies"
In article , Jason Friedman wrote: > > That is right; I would also add that it may be overwhelming for a newbie > > to be reading through a large "wall of text" -- here you have blank > > space after the current paragraph so the attention is focused even more > > on the last few lines. > > > > Additionally, since instructions scroll automatically, I can space them > > out more than you would conventionally do in a manual. > > > > Pretty cool. When reading the source of the Web page which shows the scroll, I can't find the reference to the text displayed. Only "text"... How may we use the software which generates the Javascript ? Thanks, it's cool. franck -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python training "text movies"
In article , Mitya Sirenef wrote: > On 01/14/2013 01:34 AM, Franck Ditter wrote: > > In article , > > Jason Friedman wrote: > > > >>> That is right; I would also add that it may be overwhelming for a newbie > >>> to be reading through a large "wall of text" -- here you have blank > >>> space after the current paragraph so the attention is focused even more > >>> on the last few lines. > >>> > >>> Additionally, since instructions scroll automatically, I can space them > >>> out more than you would conventionally do in a manual. > >>> > >> Pretty cool. > > When reading the source of the Web page which shows the scroll, > > I can't find the reference to the text displayed. Only "text"... > > How may we use the software which generates the Javascript ? > > Thanks, it's cool. > > > > franck > > Thanks! > > the text is in var commands = ... > > You can download the generator script here: > > https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > > (you also need to grab tmovies dir) When looking at the source of the page : http://lightbird.net/larks/tmovies/strings.html I find commands = [] I can't guess where the strings displayed come from... franck -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python training "text movies"
In article , Mitya Sirenef wrote: > On 01/19/2013 04:32 AM, Franck Ditter wrote: > > In article , > > Mitya Sirenef wrote: > > > >> On 01/14/2013 01:34 AM, Franck Ditter wrote: > >>> In article , > >>>Jason Friedman wrote: > >>> > >>>>> That is right; I would also add that it may be overwhelming for a newbie > >>>>> to be reading through a large "wall of text" -- here you have blank > >>>>> space after the current paragraph so the attention is focused even more > >>>>> on the last few lines. > >>>>> > >>>>> Additionally, since instructions scroll automatically, I can space them > >>>>> out more than you would conventionally do in a manual. > >>>>> > >>>> Pretty cool. > >>> When reading the source of the Web page which shows the scroll, > >>> I can't find the reference to the text displayed. Only "text"... > >>> How may we use the software which generates the Javascript ? > >>> Thanks, it's cool. > >>> > >>> franck > >> Thanks! > >> > >>the text is in var commands = ... > >> > >> You can download the generator script here: > >> > >> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > >> > >> (you also need to grab tmovies dir) > > When looking at the source of the page : > > http://lightbird.net/larks/tmovies/strings.html > > I find commands = [] > > I can't guess where the strings displayed come from... > > > > franck > > Look 10 lines below that line. > > > I have also added a related page that allows you to paste your own > text to make a movie; it's linked from the same page with the > list of generated t-movies. > > (that page does not let you use typewriter effect or custom pauses > though). > > - mitya I'm probably blind but 10 line after the line "commands = []", I find : var commands = [ [ "text", " " ], [ "text", " " ], ] but nothing concrete ! How come ? franck -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python training "text movies"
In article , Franck Ditter wrote: > In article , > Mitya Sirenef wrote: > > > On 01/19/2013 04:32 AM, Franck Ditter wrote: > > > In article , > > > Mitya Sirenef wrote: > > > > > >> On 01/14/2013 01:34 AM, Franck Ditter wrote: > > >>> In article , > > >>>Jason Friedman wrote: > > >>> > > >>>>> That is right; I would also add that it may be overwhelming for a > > >>>>> newbie > > >>>>> to be reading through a large "wall of text" -- here you have blank > > >>>>> space after the current paragraph so the attention is focused even > > >>>>> more > > >>>>> on the last few lines. > > >>>>> > > >>>>> Additionally, since instructions scroll automatically, I can space > > >>>>> them > > >>>>> out more than you would conventionally do in a manual. > > >>>>> > > >>>> Pretty cool. > > >>> When reading the source of the Web page which shows the scroll, > > >>> I can't find the reference to the text displayed. Only "text"... > > >>> How may we use the software which generates the Javascript ? > > >>> Thanks, it's cool. > > >>> > > >>> franck > > >> Thanks! > > >> > > >>the text is in var commands = ... > > >> > > >> You can download the generator script here: > > >> > > >> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > > >> > > >> (you also need to grab tmovies dir) > > > When looking at the source of the page : > > > http://lightbird.net/larks/tmovies/strings.html > > > I find commands = [] > > > I can't guess where the strings displayed come from... > > > > > > franck > > > > Look 10 lines below that line. > > > > > > I have also added a related page that allows you to paste your own > > text to make a movie; it's linked from the same page with the > > list of generated t-movies. > > > > (that page does not let you use typewriter effect or custom pauses > > though). > > > > - mitya > > I'm probably blind but 10 line after the line "commands = []", I find : > > var commands = [ > [ > "text", > " " > ], > [ > "text", > " " > ], > ] > > but nothing concrete ! How come ? > > franck OK OK found ! Thanks. franck -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python training "text movies"
In article , Franck Ditter wrote: > In article , > Franck Ditter wrote: > > > In article , > > Mitya Sirenef wrote: > > > > > On 01/19/2013 04:32 AM, Franck Ditter wrote: > > > > In article , > > > > Mitya Sirenef wrote: > > > > > > > >> On 01/14/2013 01:34 AM, Franck Ditter wrote: > > > >>> In article , > > > >>>Jason Friedman wrote: > > > >>> > > > >>>>> That is right; I would also add that it may be overwhelming for a > > > >>>>> newbie > > > >>>>> to be reading through a large "wall of text" -- here you have blank > > > >>>>> space after the current paragraph so the attention is focused even > > > >>>>> more > > > >>>>> on the last few lines. > > > >>>>> > > > >>>>> Additionally, since instructions scroll automatically, I can space > > > >>>>> them > > > >>>>> out more than you would conventionally do in a manual. > > > >>>>> > > > >>>> Pretty cool. > > > >>> When reading the source of the Web page which shows the scroll, > > > >>> I can't find the reference to the text displayed. Only "text"... > > > >>> How may we use the software which generates the Javascript ? > > > >>> Thanks, it's cool. > > > >>> > > > >>> franck > > > >> Thanks! > > > >> > > > >>the text is in var commands = ... > > > >> > > > >> You can download the generator script here: > > > >> > > > >> https://github.com/pythonbyexample/PBE/blob/master/code/jstmovie.py > > > >> > > > >> (you also need to grab tmovies dir) > > > > When looking at the source of the page : > > > > http://lightbird.net/larks/tmovies/strings.html > > > > I find commands = [] > > > > I can't guess where the strings displayed come from... > > > > > > > > franck > > > > > > Look 10 lines below that line. > > > > > > > > > I have also added a related page that allows you to paste your own > > > text to make a movie; it's linked from the same page with the > > > list of generated t-movies. > > > > > > (that page does not let you use typewriter effect or custom pauses > > > though). > > > > > > - mitya > > > > I'm probably blind but 10 line after the line "commands = []", I find : > > > > var commands = [ > > [ > > "text", > > " " > > ], > > [ > > "text", > > " " > > ], > > ] > > > > but nothing concrete ! How come ? > > > > franck > > OK OK found ! Thanks. > >franck When executing jstmovie.py, it complains : 'template.html' not found in tmovies... franck tmovies/template.html -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python training "text movies"
Ok I can make my way with jstmovie. Some remarks and questions : - Use encoding='utf-8' inside open of method __init__ of class Tutorial in jstmovie.py. Otherwise foreign languages are stuck. - To use the software outside Python, we need to have proper indentation as real spaces. We should be able to distinguish Arial type for usual text and fixed font for code. - Should have some colors. Wadda wadda yadda # blue annotation Cool and useful software, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python training "text movies"
In article , Mitya Sirenef wrote: > > - To use the software outside Python, we need to have proper indentation > > as real spaces. We should be able to distinguish Arial type for usual > > text and fixed font for code. > > > Not sure I understand about indentation.. You mean like wrapping > everything in a textarea tag? Right now everything is in div, > which leads to all spaces being compressed in html when viewed. SOme spaces are translated in , others in actual spaces. Say for Scheme, if I write this in foo.txt : > (define z (* 3+2i 1+i)) ; notation a+bi abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz I get this in foo.html (spaces missing) : > (define z (* 3+2i 1+i)) ; notation a+bi abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz franck -- http://mail.python.org/mailman/listinfo/python-list
Buffering in Wing and IDLE 3
Hi, I'm using Python 3.2.x with beginners. If I try the following in IDLE 3, it works as expected : from time import sleep import sys for i in range(4) : sys.stdout.write(str(i)) sys.stdout.flush() sleep(1) but with Wing-101, it write 0123 after the total sleep time. Why ??? I would prefer to use IDLE but as we are in France, the Python team does not seem to be aware that the ~ and others are not available on MacOS-X here (probably the same in Europe)... franck -- http://mail.python.org/mailman/listinfo/python-list
Stopping a looping computation in IDLE 3.2.x
How do you stop a looping computation with IDLE 3.2.x on MacOS-X Lion ? It hangs with the colored wheel... Ctl-C does not work. Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Complexity question on Python 3 lists
What is the cost of calling primes(n) below ? I'm mainly interested in knowing if the call to append is O(1), even amortized. Do lists in Python 3 behave like ArrayList in Java (if the capacity is full, then the array grows by more than 1 element) ? def sdiv(n) : # n >= 2 """returns the smallest (prime) divisor of n""" if n % 2 == 0 : return 2 for d in range(3,int(sqrt(n))+1,2) : if n % d == 0 : return d return n def isPrime(n) : """Returns True iff n is prime""" return n >= 2 and n == sdiv(n) def primes(n) : # n >= 2 """Returns the list of primes in [2,n]""" res = [] for k in range(2,n+1) : if isPrime(k) : res.append(k)# cost O(1) ? return res Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Buffering in Wing and IDLE 3
In article ,
Ned Deily wrote:
> http://www.activestate.com/activetcl/downloads
GREAT ! It seems to work.
At least, I can now get the ~ char in France from within IDLE.
A big step for manking :-)
Thanks folks,
franck
--
http://mail.python.org/mailman/listinfo/python-list
Question on Python 3 shell restarting
How may I get a fresh Python shell with Idle 3.2 ? I have to run the same modules several times with all variables cleared. Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Python 3 shell restarting
In article <19745339.1683.1333981625966.JavaMail.geo-discussion-forums@yncc41>, Miki Tebeka wrote: > > How may I get a fresh Python shell with Idle 3.2 ? > Open the configuration panel (Options -> Configure IDLE). > Look in the "Keys" tab for the shortcut to "restart-shell" Fine, thanks, but WHY isn't it in a menu (e.g. Debug) ? Moreover, I see : restart-shell - Hum, but when I press, Ctl-F6, nothing happens !!??!! F6 gives me char. (MacOS-X Lion, France, Idle 3.3.0a2) I tried to replace "restart-shell " with F6 (which does nothing except displaying a strange character inside a square), but that was refused "already in use"... franck P.S. There is no "configuration panel (Options -> Configure IDLE)", only a Preferences menu with a "Key" tab on MacOS-X. May I suggest to the Python Idle 3 team to test their software on a Mac ? Please :-) -- http://mail.python.org/mailman/listinfo/python-list
Installing pygame on MacOS-X Lion with Python 3.3
I can't get it working : "No pygame module"... Tried without success : pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg I am using Python 3 last version on MacOS-X Lion. Where is a step-by-step installation procedure ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
How to launch idle -n on windows ?
I have some problems with Python 3.2 on Windows. I want to use the turtle package, works fine, but I can't close the turtle windows. On MacOS-X, I launch idle -n and it's fine. How can I do that on Windows ? Thanks, fd -- http://mail.python.org/mailman/listinfo/python-list
Python and Lisp : car and cdr
Hi, I'm just wondering about the complexity of some Python operations to mimic Lisp car and cdr in Python... def length(L) : if not L : return 0 return 1 + length(L[1:]) Should I think of the slice L[1:] as (cdr L) ? I mean, is the slice a copy of a segment of L, or do I actually get a pointer to something inside L ? Is the above function length O(n) or probably O(n^2) ? Where are such implementation things (well) said ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPad 2.7.1 Update 4 (Python on iPad and iPhone)
Any Python 3 planned ? franck In article , AlienBaby wrote: > On Jun 23, 2:07 pm, Jon Dowdall > wrote: > > Hi All, > > > > I'm pleased to announce that PyPad (Python environment for iOS) 2.7.1 > > Update 4 is now available in the iTunes App Store. New in this version > > is the ability to create custom modules. Modules can be independent or > > can include other user modules to build larger frame works. > > > > Plans for future versions include: > > Improved cursor handling in interactive mode. > > Access to the interactive command history. > > Modules to access iOS specific functionality. > > Additional documentation. > > Syntax highlighting. > > Improved script debugging support. > > > > Regards, > > > > Jon > > Hi Jon, > > I would be interested in having a play with this. How is it restricted > when running in the iPad? > > thanks, > > Matt. -- http://mail.python.org/mailman/listinfo/python-list
Python in CS1
Except at MIT, who knows some good CS1 references for teaching Python ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Importing a class without knowing the module
Hello, I'm developing a small XML marshaller and I'm facing an annoying issue. Here's some sample code: ### My test application class Foo(object): #The class I'd like to serialize pass import myMarshaller foo = Foo() s = myMarshaller.dumps(foo) #works fine, spits something like another_foo = loads(s) #fails, see below ### My marshaller (in its own module) def loads(s): #First, get class name (here "Foo") klass = eval(className) #fails because "Foo" is not in the marshaller's namespace ! How could I tell the marshaller to locate the Foo class and any other class I try to deserialize ? I've tried to pass my test application's globals() to the marshaller, it works but it's dirty IMHO... I've tried also to locate the class (here "Foo") somewhere in sys.modules in the "loads" method, but it was heavy and unsuccessful. Thanks a lot for your help ! Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing a class without knowing the module
I thought about it, but it would make the XML file depend on the machine... no more portability... On 11/18/05, Mike Meyer <[EMAIL PROTECTED]> wrote: > Franck PEREZ <[EMAIL PROTECTED]> writes: > > ### My test application > > class Foo(object): > > #The class I'd like to serialize > > pass > > > > import myMarshaller > > foo = Foo() > > s = myMarshaller.dumps(foo) #works fine, spits something like > class = "Foo"...> > > another_foo = loads(s) #fails, see below > > > > ### My marshaller (in its own module) > > def loads(s): > > #First, get class name (here "Foo") > > klass = eval(className) #fails because "Foo" is not in the > > marshaller's namespace ! > > > > How could I tell the marshaller to locate the Foo class and any other > > class I try to deserialize ? > > How about adding Foo.__file__ to the serialized data? > > -- > Mike Meyer <[EMAIL PROTECTED]> > http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing a class without knowing the module
On 11/18/05, Mike Meyer <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] (Alex Martelli) writes: > > Mike Meyer <[EMAIL PROTECTED]> wrote: > >... > >> >> >> How about adding Foo.__file__ to the serialized data? > >... > >> >> depends on somewhere on it. You can use the module name if you have it > >> >> available. If not, deriving the module name from the file name is > >> >> about the best you can do. > >> > I disagree with the last sentence. From a filepath of > >... > >> You should read the next-to-last sentence, which says to use the > >> module name if you have it. The last sentence starts "If not" - > >> meaning you don't have the module name. *That's* the case for which > >> the file name is about the best you can do. > > I see! Thanks for clarifying. Could you please give me an example of a > > Foo class which has a Foo.__file__ attribute but not a Foo.__module__ > > attribute? Sorry, must be some moment of weakness on my mind's part > > (quite possible, since I am recovering from recent surgery), but I > > cannot think of a situation where that would be the case (while classes > > with __module__ and w/o __file__ are the normal situation). Were there > > no case in which, given a class, you can learn about its file (by a > > __file__ attribute) but not about its module (by a __module__ > > attribute), I would of course hope that my inability to parse that > > sentence of yours, which would under such hypothetical circumstaces be > > an absurd hypothesis, might be more forgivable. > > A classes __module__ attribute doesn't always tell you the name of the > module - or at least, not a name that would be usefull for the the OPs > use case. That's the case where you don't have the module name. The > reference to a classes __file__ attribute was meant to be to the > modules __file__ attribute - I'm surprised that no one picked up on > that. Again, assuming that the module has an __file__ attribute at > all. Getting the __file__ attribute to a module you don't know the > name of is a bit tricky, but possible. > > -- > Mike Meyer <[EMAIL PROTECTED]> > http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for your answers. And btw, sorry for top-posting, I'll be more careful next time. -- http://mail.python.org/mailman/listinfo/python-list
Re: books: Dive into Python vs Beginning Python
On 11/25/05, Sebastien Douche <[EMAIL PROTECTED]> wrote: > On 11/25/05, Franz Mueller <[EMAIL PROTECTED]> wrote: > > Hi, > > Hi Franz! :) > > > which of the following books would you recommend: > > "Dive into Python" or "Beginning Python: From Novice to Professional"? > > Both are very good books but I suggest the latter because more recent. > Beginning Python talk python 2.3 and 2.4 : set data structure, > generator, iterator... > "Dive into Python" actually mentions generators : http://diveintopython.org/dynamic_functions/stage6.html And it's a very well written book btw. -- http://mail.python.org/mailman/listinfo/python-list
[PyGTK] forbid focus of TreeView columns
Hi all,
I'm building a PyGTK interface in which I would like that no widget
would be able to get the focus (and so to be activated by pressing the
Return key). For this purpose, for each widget, I do:
widget.set_property("can-focus", gtk.FALSE)
My problem is a TreeView which has a clickable column, it get the
default focus and I did not find how to forbid that.
I tried:
def focus (widget, *args) :
try :
widget.set_property("can-focus", gtk.FALSE)
except :
pass
try :
widget.set_property("can-default", gtk.FALSE)
except :
pass
win.forall(focus)
where win is my application window (I also tried on the TreeView) but it
doesn't work. :-(
I also tried with widget.unset_flags, same result. :-((
If I choose another widget and give it the default focus
(widget.grab_default and widget.grab_focus) it's OK until I click on the
column which then keeps the focus. :-(((
I'm sure I could capture the Return key but I don't want to have this
dashed line around the focused widget...
I think that this column has somewhere an associated widget but I could
not find it anywhere (and neither could win.forall).
I'm using PyGTK-2.0.0 and cannot use another version.
Thanks in advance for any idea!
Franck
--
http://mail.python.org/mailman/listinfo/python-list
[PyGTK] Resizing a HandleBox
Hi all, I'm using PyGTK-2.0.0, when I detach a HandleBox, the resizing of the newly created window is broken: it can be resized but it's content (the HandleBox and its child) is not affected at all and is not resized. Does any one have a solytion to this problem? Thanks in advance! Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting sizes of widgets (PyGTK)
Harlin Seritt wrote:
I have the following code and I would like to know how to set the
length and width of widgets like Buttons. When the window opens the
button fills up the space even though I have told it not to.
Your button is stretched horizontally because there is nothing to put
around it in order to fill the space. Try to embed it into a HBox,
surrounded by empty labels :
import pygtk, gtk
class Greeter:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.box = gtk.VBox()
self.window.add(self.box)
self.label = gtk.Label("Please enter your name in the box
below:")
self.namebox = gtk.Entry(12)
self.button = gtk.Button("Greet Me!")
self.output = gtk.Label("Your output will appear here.")
hbox = gtk.HBox()
self.box.pack_start(self.label, False, False, 2)
self.box.pack_start(self.namebox, False, False, 2)
hbox.add(gtk.Label())
hbox.pack_start(self.button, False, False, 2)
hbox.add(gtk.Label())
self.box.pack_start(hbox, False, False, 2)
self.box.pack_start(self.output, False, False, 2)
self.window.show_all()
def main(self):
gtk.main()
a = Greeter()
a.main()
Cheers,
Franck
--
http://mail.python.org/mailman/listinfo/python-list
Re: Functional Programming and python
In article , rusi wrote: > Combining your two questions -- Recently: > What minimum should a person know before saying "I know Python" > > And earlier this > On Sunday, August 4, 2013 10:00:35 PM UTC+5:30, Aseem Bansal wrote: > > If there is an issue in place for improving the lambda forms then that's > > good. I wanted a link about functional programming because it is mentioned > > as > > if it were a household word. > > Python is not a functional programming language; however it supports most of > FP better than traditional languages like C/Java. > eg with iterators/generators + itertools + functools you can do most of what > lazy lists give in haskell > > Some discussion here: > http://stackoverflow.com/questions/1017621/why-isnt-python-very-good-for-functional-programming > > [Not everything said there is correct; eg python supports currying better > than haskell which is surprising considering that Haskell's surname is Curry!] > > So if I may break your question into two: > 1. Why should a programmer of a non-FP language know FP? > 2. What in FP should a (any|all) programmer know? > > I touched upon these in two blog-posts: > 1. http://blog.languager.org/2013/06/functional-programming-invades.html > 2. http://blog.languager.org/2012/10/functional-programming-lost-booty.html > > Also most programmers without an FP background have a poor appreciation of > the centrality of recursion in CS; see > http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html Good approach of FP in Python, but two points make me crazy : 1. Tail recursion is not optimized. We are in 2013, why ? This is known technology (since 1960). And don't answer with "good programmers don't use recursion", this is bullshit. 2. Lambda-expression body is limited to one expression. Why ? Why the hell those limitations ? In this aspect, Javascript has a cooler approach. franck -- https://mail.python.org/mailman/listinfo/python-list
Re: closure = decorator?
In article <[email protected]>, Steven D'Aprano wrote: > On Fri, 11 Oct 2013 10:14:29 +0300, Jussi Piitulainen wrote: > > > Roy Smith writes: > >> In article , > >> Piet van Oostrum wrote: > >> > >> > I usually say that a closure is a package, containing a function with > >> > some additional data it needs. The data usually is in the form of > >> > name bindings. > >> > >> That's pretty close to the way I think about it. The way it was > >> originally described to me is, "A closure is a function bundled up with > >> it's arguments". > > > > Really? It should be more like "a function bundled up with some other > > function's arguments" and even more like "a function bundled up with > > bindings for its free variables". > > Closures have nothing to do with *arguments*. A better definition of a > closure is that it is a function together with a snapshot of the > environment it was called from. > > def func(arg): > y = arg + 1 > def inner(): > return y + 1000 > return inner > > f = func(1) Maybe a better example of closure would be (just for the nonlocal) : def fib() : (a,b) = (0,1) def producer() : nonlocal a,b # Python 3 old = a (a,b) = (b,a+b) return old return producer >>> f = fib() >>> [f() for i in range(10)] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] > At this point, f is a closure. It needs to know the value of y (not the > argument to func) in order to work, and the implementation is to store > that information inside f.func_closure (or f.__closure__ in Python 3). > The part of the calling environment which is saved is y Shouldn't it be the (a,b) pair here ? But : >>> f.__closure__[0].cell_contents# access to what ? 55 Shouldn't cell_contents keep the current (a,b) pair, a part of the snapshot of the creation environment (private variables of the closure) ? Instead it seems to returns only a (which is the next production)... franck -- https://mail.python.org/mailman/listinfo/python-list
Can't get tilde character with IDLE 3.2.2 on French Mac Lion
Hi ! All is in the subject. I'm starting to use Python with Idle 3.2.2 on MacOS-X Lion (French). I can't get "Option-N space" to provide the ~ char. I tried to go into the Keys preferences but I can't find "Option-N space" to modify its meaning. Its actual behavior is to merge lines of a paragraph. Thanks for help ! franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't get tilde character with IDLE 3.2.2 on French Mac Lion
Nope, "space" followed by "Shift-Option-N" gives a greek iota... I tried other combinations, unsuccessfully. IDLE 3 (French) seems to be unusable as we use many ~ in web applications :-( Should we hope a fix soon, or leave IDLE ? Thanks, franck In article , Ned Deily wrote: > In article , > Franck Ditter wrote: > > All is in the subject. I'm starting to use Python with Idle 3.2.2 > > on MacOS-X Lion (French). I can't get "Option-N space" to provide > > the ~ char. > > I tried to go into the Keys preferences but I can't find "Option-N space" > > to modify its meaning. Its actual behavior is to merge lines of a > > paragraph. > > You are likely running into a current problem in the OS X Cocoa version > of Tcl/Tk 8.5 as included with Lion and as shipped by ActiveState. > Previously, if you tried to type composite characters, like Option N, > the Cocoa Tcl/Tk would crash. Pending a real fix, a patch was made to > Tcl/Tk 8.5 to discard composite characters rather than crash. You > should be able to get a tilde by using the post-composite keyboard > sequence: try typing "space" followed by "Shift-Option-N". > > http://sourceforge.net/tracker/index.php?func=detail&aid=2907388&group_id=12997&atid=112997 -- http://mail.python.org/mailman/listinfo/python-list
[ANN] XML Serializer module
Dear all, I wished to announce here my first Python module : XML Serializer. It recursively serializes and deserializes Python objects and their children. Children may be an instance's attributes, or list/dict/tuple elements. When serializing an instance, you may customize the attributes which are dumped, and the constructor values. In simple cases, the module finds out the constructor attributes by itself. You may download the module here, and see documentation and examples : http://eleves.ec-lille.fr/~perezf/python/ Any comment welcomed ! Franck -- http://mail.python.org/mailman/listinfo/python-list
Proper way of handling "plug-in" methods
All,
My application deals with strings formatting. I have built-in methods
but I also expect the user to add its methods in its own .py files
(some sort of plugin methods, all user methods should be exposed in my
application).
Here is the structure I have thought of :
formatting.py
_formattingDict = {} #a dict composed of all available methods, both
builtin and user
def expose(...) : #adds a method to the dict
builtinformatting.py
import myapp.formatting.expose
@expose
def builtinMethod(inputStr) : return someOutput
/home/user/.myapp/customformatting.py
import myapp.formatting.expose
@expose
def customMethod(inputStr) : return someOutput
model.py
#References all the methods, both builtin and custom
execfile("builtinformatting.py")
execfile("/home/user/.myapp/customformatting.py")
Expected result after the execfile : formatting._formattingDict
contains the 2 methods builtinMethod and customMethod
Is this a proper way of structuring my application ? Do you see
anything better ?
Moreover, I dislike execfile("builtinformatting.py") since classic
import would do the job. However I first wanted a united method for
both builtin and custom scripts since it is the same logic for me.
Thanks very much in advance for your advice.
Franck
--
http://mail.python.org/mailman/listinfo/python-list
Automatic class attribute
Hello all, Considering the following code : class C(object): ...: observers = [] ...: ...: @classmethod ...: def showObservers(cls): ...: print cls.observers class D1(C): ...: observers = [] #could it be moved in C ? class D2(C): ...: observers = [] #could it be moved in C ? I want each child class of C to have it's own "observers" class attribute. The code I provided works... but I'd like to avoid typing "observers = []" in each child class. Is it possible to define something in C which would basically mean : "for each child class, automatically bind a new list attribute called observers" ? Are metaclasses a way ? Is it possible to avoid them ? Thanks a lot, Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Automatic class attribute
On 2/3/06, Kirk McDonald <[EMAIL PROTECTED]> wrote: > Franck PEREZ wrote: > > Hello all, > > > > Considering the following code : > > > > class C(object): > >...: observers = [] > >...: > >...: @classmethod > >...: def showObservers(cls): > >...: print cls.observers > > > > class D1(C): > >...: observers = [] #could it be moved in C ? > > > > class D2(C): > >...: observers = [] #could it be moved in C ? > > > > I want each child class of C to have it's own "observers" class attribute. > > > > The code I provided works... but I'd like to avoid typing "observers = > > []" in each child class. > > > > Is it possible to define something in C which would basically mean : > > "for each child class, automatically bind a new list attribute called > > observers" ? > > > > Are metaclasses a way ? Is it possible to avoid them ? > > Thanks a lot, > > Franck > > By an astounding coincidence, I was just working on a similar problem. > Metaclasses can do this, no problem: > > class M(type): > def __init__(cls, name, bases, dict): > cls.observers = [] > > def showObservers(cls): > print cls.observers > > class C(object): > __metaclass__ = M > > class D1(C): pass > class D2(C): pass > > -Kirk McDonald > -- > http://mail.python.org/mailman/listinfo/python-list > Works great. Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
The problem of anonymity with decorators
Dear all,
I would like to work around the "anonymizing" effect of decorators when
an exception is raised in the wrapped function. Let's consider the
following example:
def int_result (fun) :
def wrapped (*largs, **kwargs) :
result = fun(*largs, **kwargs)
if not isinstance(result, int) :
raise TypeError, "should return int"
return result
return wrapped
@int_result
def add (a, b) :
return a+b
print add(1, 2)
print add("foo", "bar")
As expected, the last line results in raising TypeError:
Traceback (most recent call last):
File "wrapping.py", line 14, in ?
print add("foo", "bar")
File "wrapping.py", line 5, in wrapped
raise TypeError, "should return int"
TypeError: should return int
My problem is that the errors comes from a function named "wrapped"
while I'd prefer to see here the name of the wrapped function. Indeed,
the code above is only a stripped down sample code but in my
application, I'll have a lot of functions, all wrapped the same way. So
I'd prefer a traceback like:
Traceback (most recent call last):
File "wrapping.py", line 14, in ?
print add("foo", "bar")
File "wrapping.py", line 8, in add (wrapped)
@int_result
TypeError: should return int
Where the exception seems to come from the point where add "was"
wrapped, instead of from the inside of the wrapper.
I tried to change wrapper.__name__ and wrapper.func_name but it does not
change the traceback, and wrapper.func_code.co_name is read-only. I also
tried, unsuccessfully, to rename functions with:
import new
def rename (fun, name) :
return new.function(fun.func_code, {}, name)
So, my questions:
- can I change a function name so that it affects the traceback when an
exception is raised in the function?
- is there some special trick to raise an exception making it, in
appearance, coming from somewhere else?
Thanks in advance for any answer.
Regards,
Franck
--
http://mail.python.org/mailman/listinfo/python-list
Re: The problem of anonymity with decorators
Alex, Michele and Skip, Many thanks for your help, I should find my way by putting all these information together. Best regards, Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: how to traverse network devices in our system?
> Yes, it is Linux. I was just googling and found that there are kudzu
> bindings for python. From that i can query kudzu for any configured and
> unconfigured device (i hope so). is there any other method available
> other kudzu python bindings ?
I do it using DBus/Hal, for instance:
###
import dbus
system_bus = dbus.SystemBus()
hal_manager_obj = system_bus.get_object('org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
hal_manager = dbus.Interface(hal_manager_obj,
'org.freedesktop.Hal.Manager')
for udi in hal_manager.FindDeviceByCapability("net") :
obj = system_bus.get_object("org.freedesktop.Hal", udi)
dev = dbus.Interface(obj, 'org.freedesktop.Hal.Device')
print dev.GetProperty("net.interface"),
print dev.GetProperty("net.address")
###
Cheers,
Franck
--
http://mail.python.org/mailman/listinfo/python-list
Better performance
Hello Folks, I am facing a problem where i need to parse around 200 files, i have a bit of knowledge in PHP/Perl/Python (the magic P :-P) Which one would you suggest me since i have to generate a web interface ? And each one has his area of 'work' Thanks for your help ! -- http://mail.python.org/mailman/listinfo/python-list
Better performance
Hello Folks, I am facing a problem where i need to parse around 200 files, i have a bit of knowledge in PHP/Perl/Python (the magic P :-P) Which one would you suggest me since i have to generate a web interface ? And each one has his area of 'work' Thanks for your help ! -- http://mail.python.org/mailman/listinfo/python-list
Import text file
Hello, I have a text file where there is xxx=value yyy=value zzz=value etc... I would like use the from myfile import Since it has not the extension py how can i read it ? I know the way to do it with the open file but i think this one is easier... Thansk Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / glade fundamentals
> maybe you will find it easyer to use GladeGen to generate the > skeleton of your application rather then coding it yourself. Take a > look here: http://www.linuxjournal.com/article/7421 You may also use my PyGG module: http://freshmeat.net/projects/pygg Cheers, Franck -- http://mail.python.org/mailman/listinfo/python-list
[Off topic] Re: Backing Up VMWare
> Hello - has anyone written a Python script to backup VMWare servers? > If so, I'd appreciate any pointers as to how to go about doing so. Nothing to do with Python, but... Under Linux, VMware disks are mountable using the script vmware-mount.pl, see: http://www.vmware.com/support/reference/linux/loopback_linux.html Franck -- http://mail.python.org/mailman/listinfo/python-list
Re: [RELEASE] Python 2.7 release candidate 1 released
Just an advice as I see that "old" Python is maintained. When starting with Python (simple programs and GUIs) should I start with Python 3.x ? If it has a decent implementation on Mac/Linux/Windows of course... Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Noob question on 2 vs 3 Python releases
Pardon my noobness (?) but why is there a 2.x and 3.x development teams working concurrently in Python ? I hardly saw that in other languages. Which one should I choose to start with, to cope with the future ? Isn't 3.x supposed to extend 2.y ? This situation is very strange... Thanks for your explanations... franck -- http://mail.python.org/mailman/listinfo/python-list
