executing arbitrary statements
Hello everyone, I'm probably missing something pretty obvious, but I was wondering if there was a way of executing an arbitrary line of code somehow (such as a line of code based on user-input). There's the obvious use of "eval" that will evaluate a function call, but that doesn't allow all things. For instance: >>> import sys >>> eval(r"sys.stdout.write('Hello world!\n')") Hello world! >>> eval(r"print 'Hello world!'") Traceback (most recent call last): File "", line 1, in File "", line 1 print 'Hello world!' ^ SyntaxError: invalid syntax >>> Because write is a function eval works fine for it. But since print isn't (2.7), it throws a syntax error. Likewise, variable assignments aren't allowed either as they are also not functions and lack a return value: >>> eval("j = 1") Traceback (most recent call last): File "", line 1, in File "", line 1 j = 1 ^ SyntaxError: invalid syntax What I'm more or less looking to do is present a (limited) form of an interpreter inside the application I'm writing for the advanced user. I'm also interested to hear if this is a particularly bad idea for any reason, and if there are security issues involved with allowing users to execute their own code inside my program (keeping in mind that some people may "donate" their scripts to others that may run them as black boxes). Is it enough to disallow import statements, thereby not giving direct access to the sys and os modules? I know more or less what I want to do, but I'd also appreciate any experienced input/advice/suggestions. Thanks! Jason -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
> > On Sep 29, 10:23 pm, rantingrick wrote: > > > What is so bad about breaking code in obscure places? > On Sep 29, 9:50 pm, alex23 wrote: > > Try coding in PHP across minor release versions and see how you feel > > about deprecating core functions on a whim. On Sep 30, 11:54 pm, rantingrick wrote: > I never said we should remove it now, i said we should deprecate it > now. Actually, *I* said deprecate, *you* said break. I don't see the word 'remove' anywhere in my comment. > Please Google deprecate. Please read what I wrote rather than what you want me to have said. > Well "alex" i can't see a mob approaching with pitchforks because we > deprecate a misplaced and rarely used functionality of the stdlib. No, but you don't see a lot of things. You're genuinely convinced that your viewpoint is superior and singularly correct. I don't think you're a reasonable arbiter of what functionality should be added or removed from the stdlib. > Well "alex", like yourself, i hold expertise in many fields BESIDES > programming. One of which being psychology. That only makes the claims that you regularly post about others even more offensive. -- http://mail.python.org/mailman/listinfo/python-list
Re: overloading operators for a function object
On Fri, Sep 30, 2011 at 9:50 PM, Fletcher Johnson wrote: > Is it possible to overload operators for a function? > > For instance I would like to do something roughly like... > > def func_maker(): > def func(): pass > > def __eq__(other): > if other == "check": return True > return False > > func.__eq__ = __eq__ > return func > > newfunc = func_maker() > newfunc == "check" #true > newfunc == "no" #false You can write a callable [wrapper] object to get the same effect: class SpecialFunction(object): def __call__(self, actual, args, go, here): return whatever def __eq__(self, other): return other == "check" newfunc = SpecialFunction() newfunc == "check" # => True newfunc(1, 2, 3, 4) #=> whatever Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
overloading operators for a function object
Is it possible to overload operators for a function? For instance I would like to do something roughly like... def func_maker(): def func(): pass def __eq__(other): if other == "check": return True return False func.__eq__ = __eq__ return func newfunc = func_maker() newfunc == "check" #true newfunc == "no" #false -- http://mail.python.org/mailman/listinfo/python-list
RE: [OT] Off-Topic Posts and Threads on the Python Mailing List
Lol you all sound like google's angry birds with their feathers ruffled by a comment. You guys should open up another mailing list to extinguish your virtually bruised egos. . . . On Sep 30, 2011 10:27 PM, "Prasad, Ramit" wrote: -- http://mail.python.org/mailman/listinfo/python-list
Re: Python without a tty
On 30/09/11 20:34:37, RJB wrote: You could try the old UNIX "nohup ...&" technique for running a process in the background (the&) with no HangUP if you log out: $ nohup python -c "import sys,os; print os.isatty(sys.stdout.fileno())"& appending output to nohup.out $ cat nohup.out False But that is over kill I guess. One worrying detail the definition of a running process in UNIX implies is that it has standard input/output files open. You'd be wise to make sure that they are connected to things that are safe /dev/null. Even so /dev/tty can be opened any way... Not if you really detach from your tty: after you've detached, there is no tty for /dev/tty to connect to and any attempt to open it will raise IOError. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: Simplest way to resize an image-like array
On Sep 30, 5:40 pm, John Ladasky wrote: > Hi folks, > > I have 500 x 500 arrays of floats, representing 2D "grayscale" images, > that I need to resample at a lower spatial resolution, say, 120 x 120 > (details to follow, if you feel they are relevant). > > I've got the numpy, and scipy, and matplotlib. All of these packages > hint at the fact that they have the capability to resample an image- > like array. But after reading the documentation for all of these > packages, none of them make it straightforward, which surprises me. > For example, there are several spline and interpolation methods in > scipy.interpolate. They seem to return interpolator classes rather > than arrays. Is there no simple method which then calls the > interpolator, and builds the resampled array? > > Yes, I can do this myself if I must -- but over the years, I've come > to learn that a lot of the code I want is already written, and that > sometimes I just have to know where to look for it. > > Thanks! Is something like http://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.imresize.html#scipy.misc.imresize any use? -- http://mail.python.org/mailman/listinfo/python-list
Re: Modifying external running process using python
On Thu, 29 Sep 2011 23:02:55 -0700, bingbang wrote: > Beginner here. I am trying to figure out how to modify a running > process on a linux system using Python. > I looked up trace and some other modules but they all seem to do with > following the currently executing python process. ptrace() is the system call which programs such as gdb, strace, ltrace, etc use to monitor or control another process. You wil probably need to use ctypes to access this function from Python. > Let's assume I have sudo/root privileges and that the POC code "only > needs to work in linux". You don't need root privilege to ptrace() a process which you own and which isn't privileged (a process which starts out setuid/setgid is still treated as privileged even if it reverts to the real user/group IDs). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python without a tty
On Thu, 29 Sep 2011 11:53:12 +0200, Alain Ketterlin wrote: >> I have a Python script which I would like to test without a tty attached >> to the process. I could run it as a cron job, but is there an easier way? >> >> I am running Linux. > > Isn't os.setsid() what you're looking for? It makes the calling process > have no controlling terminal. There's also a user command called setsid > that should have the same effect. setsid() requires that the calling process isn't a process group leader; this can be achieved by fork()ing. The setsid command does this automatically. As you say, this ensures that the process has no controlling terminal (i.e. it won't get signals from the tty driver for ^C, ^Z, hangup, etc). It won't detach stdin etc from a terminal. Also, open()ing a tty will result in it becoming the controlling terminal unless O_NOCTTY is used. I suspect that the OP just wants e.g.: script.py &>/dev/null <&- which will redirect stdout and stderr to /dev/null and close stdin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
Meh, so run your own web-server. If wave isn't right, search on sourceforge for a while. On 10/1/11, Prasad, Ramit wrote: >>> The answer to any news/mail client with feature X type question is >>> normally "gnus" - although I don't know what "Gmail-like style" is. >>Yeah > > Gah, I got distracted mid-email and forgot to finish. What I wanted to say > was, "Yeah, not knowing what 'Gmail-like style' makes a big difference ;)". > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > > > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Fri, Sep 30, 2011 at 11:08:16AM -0700, rantingrick wrote: > On Sep 30, 11:36 am, Westley Martínez wrote: > > On Fri, Sep 30, 2011 at 09:22:59AM -0700, rusi wrote: > > > On Sep 30, 8:58�pm, Neil Cerutti wrote: > > > > On 2011-09-30, DevPlayer wrote: > > > > > > > I still assert that contradiction is caused by narrow perspective. > > > > > > > By that I mean: just because an objects scope may not see a certain > > > > > condition, doesn't mean that condition is non-existant. > > > > > > > I also propose that just because something seems to contradict doesn't > > > > > mean it is false. Take for instance: > > > > > > > Look out your window. Is it daylight or night time? You may say > > > > > it is daylight or you may say it is night time. I would > > > > > disagree that only one of those conditions are true. Both > > > > > conditions are true. Always. It is only day (or night) for YOU. > > > > > But the opposite DOES in fact exist on the other side of the > > > > > world at the same time. > > > > > > > I call this Duality of Nature (and I believe there was some > > > > > religion somewhere in some time that has the same notion, > > > > > Budism I think but I could be mistaken). I see such > > > > > "contradictions" in what appears to be most truths. > > > > > > You are not alone. Many ancient philosophers, fathers of > > > > religious and scientific thought, thought the same. > > > > > > They thought that contradictory qualities could exist in objects > > > > simultaneously. For example, they thought that a cat was both big > > > > and small, because it was big compared to a mouse and small > > > > compared to a house. They didn't notice that big and small were > > > > not poperties of the cat, at all but were instead statements > > > > about how a cat relates to another object. > > > > > > When you say, "It is night," you are making an assertion about a > > > > position on the surface of the earth and its relationship to the > > > > sun. > > > > > > If you are not discussing a specific a position on the Earth, > > > > then you cannot make a meaningful assertion about night or day at > > > > all. Night and Day are not qualities of the entire Earth, but > > > > only of positions on the Earth. > > > > > But just imagine that we were all pre-galiliean savages -- knowing > > > nothing about the roundness of the earth, the earth going round and so > > > on and somehow you and I get on the phone and we start arguing: > > > Rusi: Its 9:30 pm > > > Neil: No its 12 noon > > > > > How many cases are there? > > > We both may be right, I may be wrong (my watch may have stopped) or we > > > both etc > > > > > ie conflicting data may get resolved within a larger world view (which > > > is what devplayer is probably saying). > > > > > Until then it is wiser to assume that that larger world view exists > > > (and I dont yet know it) > > > than to assume that since I dont know it it does not exist. > > > > > For me (admittedly an oriental) such agnosticism (literally "I-do-not- > > > know-ness") is as much a foundation for true religiosity as effective > > > science > > > > I.e. humility? > > @DevPlayer, rusi, Neil, Wes, and group > > Yes, there are two views of reality; that of the absolute and that of > the relative. Both are true. It is always daytime and nighttime > simultaneously; if you look at things from a global perspective. > > However, the true nature of "daytime vs nighttime" is purely a > relative observation. The fact that both exist does not falsify the > validity of the relative view. Recognizing the paradox is important > and proves you are not confined to your own selfish view points and > are in fact an intelligent being What paradox?. -- http://mail.python.org/mailman/listinfo/python-list
Re: Motion Tracking with Python
/How was her project received at school?/ She got an "Outstanding" blue ribbon award. The teachers were impressed. (It was only a mandatory school project; it was not part of a regional competition or anything fancy like that.) --Derek On 09/30/2011 09:40 AM, Irmen de Jong wrote: On 30-9-2011 4:16, Derek Simkowiak wrote: Hello, I have a neat Python project I'd like to share. It does real-time motion tracking, using the Python bindings to the OpenCV library: http://derek.simkowiak.net/motion-tracking-with-python/ There is a YouTube video showing the script in action. It's especially neat because my daughter and I worked together on this project. We used it to track her two pet gerbils, as part of her science fair project. She wrote her own (separate) Python script to read the motion tracking log files, compute distance and velocity, and then export those values in a CSV file. Like I say on the web page: "I’m convinced that Python is the best language currently available for teaching kids how to program." Wow. Very impressive and very enjoyable to read about it. How was her project received at school? Thanks a lot for sharing this. Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: Motion Tracking with Python
> /I am having problems with getting data from the CCD (basically i don't know how to do it :), can you give me a tip for doing this? Or explain how you did it please?/ I am using the OpenCV library to grab images. Here are the specific lines of code: self.capture = cv.CaptureFromCAM(0)cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, 320 );cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 240 );frame = cv.QueryFrame(self.capture) # ...this is done repeatedly in the main loop. These were copied from the examples that came with OpenCV. I don't know if this will work under Windows. The source code to my script is available online; I recommend downloading it and playing with it. Also, check out the OpenCV Python documentation. Thanks, Derek On 09/30/2011 07:06 AM, Ricardo Mansilla wrote: On Thursday 29 September 2011 21:16:52 you wrote: > Hello, > I have a neat Python project I'd like to share. It does real-time motion > tracking, using the Python bindings to the OpenCV library: > > http://derek.simkowiak.net/motion-tracking-with-python/ > > There is a YouTube video showing the script in action. > > It's especially neat because my daughter and I worked together on this > project. We used it to track her two pet gerbils, as part of her science > fair project. She wrote her own (separate) Python script to read the > motion tracking log files, compute distance and velocity, and then > export those values in a CSV file. Like I say on the web page: "I’m > convinced that Python is the best language currently available for > teaching kids how to program." > > I also use Python professionally, and it's worked out great every time. > There's no job Python can't handle. > > > Thanks, > Derek Simkowiak > http://derek.simkowiak.net Hi, this is awesome!! I'm currently working in something similar, but I am having problems with getting data from the CCD (basically i don't know how to do it :), can you give me a tip for doing this? Or explain how you did it please? I not a newbie at python but not as experienced as evidently you are. Thanks a lot in advance. -- (...)Also, since that same law states that any system able to prove its consistency to itself must be inconsistent; any mind that believes it can prove its own sanity is, therefore, insane.(...) Kurt Gödel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python without a tty
On Sep 29, 3:52 am, Steven D'Aprano wrote: > Alain Ketterlin wrote: > > Steven D'Aprano writes: > > >> I have a Python script which I would like to test without a tty attached > >> to the process. I could run it as a cron job, but is there an easier way? > > >> I am running Linux. > > > Isn't os.setsid() what you're looking for? It makes the calling process > > have no controlling terminal. There's also a user command called setsid > > that should have the same effect. > > It doesn't appear so to me. > > [steve@sylar ~]$ tty > /dev/pts/16 > [steve@sylar ~]$ setsid tty > /dev/pts/16 > > [steve@sylar ~]$ python -c "import sys,os; print > os.isatty(sys.stdout.fileno())" > True > [steve@sylar ~]$ setsid python -c "import sys,os; print > os.isatty(sys.stdout.fileno())" > True > > If I run the same Python command (without the setsid) as a cron job, I > get False emailed to me. That's the effect I'm looking for. > > -- > Steven You could try the old UNIX "nohup ... &" technique for running a process in the background (the &) with no HangUP if you log out: $ nohup python -c "import sys,os; print os.isatty(sys.stdout.fileno())" & appending output to nohup.out $ cat nohup.out False But that is over kill I guess. One worrying detail the definition of a running process in UNIX implies is that it has standard input/output files open. You'd be wise to make sure that they are connected to things that are safe /dev/null. Even so /dev/tty can be opened any way... Hope this helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Sep 30, 11:36 am, Westley Martínez wrote: > On Fri, Sep 30, 2011 at 09:22:59AM -0700, rusi wrote: > > On Sep 30, 8:58�pm, Neil Cerutti wrote: > > > On 2011-09-30, DevPlayer wrote: > > > > > I still assert that contradiction is caused by narrow perspective. > > > > > By that I mean: just because an objects scope may not see a certain > > > > condition, doesn't mean that condition is non-existant. > > > > > I also propose that just because something seems to contradict doesn't > > > > mean it is false. Take for instance: > > > > > Look out your window. Is it daylight or night time? You may say > > > > it is daylight or you may say it is night time. I would > > > > disagree that only one of those conditions are true. Both > > > > conditions are true. Always. It is only day (or night) for YOU. > > > > But the opposite DOES in fact exist on the other side of the > > > > world at the same time. > > > > > I call this Duality of Nature (and I believe there was some > > > > religion somewhere in some time that has the same notion, > > > > Budism I think but I could be mistaken). I see such > > > > "contradictions" in what appears to be most truths. > > > > You are not alone. Many ancient philosophers, fathers of > > > religious and scientific thought, thought the same. > > > > They thought that contradictory qualities could exist in objects > > > simultaneously. For example, they thought that a cat was both big > > > and small, because it was big compared to a mouse and small > > > compared to a house. They didn't notice that big and small were > > > not poperties of the cat, at all but were instead statements > > > about how a cat relates to another object. > > > > When you say, "It is night," you are making an assertion about a > > > position on the surface of the earth and its relationship to the > > > sun. > > > > If you are not discussing a specific a position on the Earth, > > > then you cannot make a meaningful assertion about night or day at > > > all. Night and Day are not qualities of the entire Earth, but > > > only of positions on the Earth. > > > But just imagine that we were all pre-galiliean savages -- knowing > > nothing about the roundness of the earth, the earth going round and so > > on and somehow you and I get on the phone and we start arguing: > > Rusi: Its 9:30 pm > > Neil: No its 12 noon > > > How many cases are there? > > We both may be right, I may be wrong (my watch may have stopped) or we > > both etc > > > ie conflicting data may get resolved within a larger world view (which > > is what devplayer is probably saying). > > > Until then it is wiser to assume that that larger world view exists > > (and I dont yet know it) > > than to assume that since I dont know it it does not exist. > > > For me (admittedly an oriental) such agnosticism (literally "I-do-not- > > know-ness") is as much a foundation for true religiosity as effective > > science > > I.e. humility? @DevPlayer, rusi, Neil, Wes, and group Yes, there are two views of reality; that of the absolute and that of the relative. Both are true. It is always daytime and nighttime simultaneously; if you look at things from a global perspective. However, the true nature of "daytime vs nighttime" is purely a relative observation. The fact that both exist does not falsify the validity of the relative view. Recognizing the paradox is important and proves you are not confined to your own selfish view points and are in fact an intelligent being. -- http://mail.python.org/mailman/listinfo/python-list
RE: Suggested coding style
>> The answer to any news/mail client with feature X type question is >> normally "gnus" - although I don't know what "Gmail-like style" is. >Yeah Gah, I got distracted mid-email and forgot to finish. What I wanted to say was, "Yeah, not knowing what 'Gmail-like style' makes a big difference ;)". Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Suggested coding style
May I suggest a[n] email client that can group mailing list threads? > The answer to any news/mail client with feature X type question is > normally "gnus" - although I don't know what "Gmail-like style" is. Yeah >slrn. Is good. Unless I am missing something, it does not do email. >http://incubator.apache.org/wave/ Are you suggesting I run my own webserver to aggregate emails, stick them in wave, and then write something that will convert my wave post to email? I suppose it could work, but that is *usually* not what is considered a "desktop app". > Maybe one Apache's Buzz? I think you will have to Google that one for me, as the first results I found were Apache Wicket and Apache Beehive...both which seem not related. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
http://incubator.apache.org/wave/ On 10/1/11, Neil Cerutti wrote: > On 2011-09-30, Paul Rudin wrote: >> "Prasad, Ramit" writes: >> May I suggest a[n] email client that can group mailing list threads? >>> >>> Please do. Bonus points if it handles threading in a Gmail-like style. >> >> The answer to any news/mail client with feature X type question is >> normally "gnus" - although I don't know what "Gmail-like style" is. > > slrn. Is good. > > -- > Neil Cerutti > "A politician is an arse upon which everyone has sat except a man." > e. e. cummings > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
On 2011-09-30, Paul Rudin wrote: > "Prasad, Ramit" writes: > >>>May I suggest a[n] email client that can group mailing list threads? >> >> Please do. Bonus points if it handles threading in a Gmail-like style. > > The answer to any news/mail client with feature X type question is > normally "gnus" - although I don't know what "Gmail-like style" is. slrn. Is good. -- Neil Cerutti "A politician is an arse upon which everyone has sat except a man." e. e. cummings -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
Maybe one Apache's Buzz? On 10/1/11, Prasad, Ramit wrote: >>> Please do. Bonus points if it handles threading in a Gmail-like style. >>> >> >>May I suggest Gmail? It handles threading in a very Gmail-like style. > > Curses, foiled by my lack of specificity! I meant desktop client. > Although...if another website does similar threading it would be good to > know. Never know when I will want to start avoiding Gmail :) > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
"Prasad, Ramit" writes: >>May I suggest a[n] email client that can group mailing list threads? > > Please do. Bonus points if it handles threading in a Gmail-like style. The answer to any news/mail client with feature X type question is normally "gnus" - although I don't know what "Gmail-like style" is. -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
rusi wrote: On Sep 30, 9:41 pm, Chris Angelico wrote: On Sat, Oct 1, 2011 at 2:38 AM, Dennis Lee Bieber wrote: And I would argue that by starting with "Look out your window..." you have explicitly excluded the rest of the world from consideration in answering; you have narrowed the focus to only the region visible from "my window". But what if I'm a great windowing magnate, owning windows all over the world? (Is anyone else amused by this thread and its ridiculosity?) ChrisA Not more ridiculous than people getting religious over not just about silly (man-made) languages but even over the editors they use No kidding! Vim is *obviously* the best one out there! *ducks and runs* ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
On Sat, Oct 1, 2011 at 3:05 AM, Prasad, Ramit wrote: > Curses, foiled by my lack of specificity! I meant desktop client. > Although...if another website does similar threading it would be good to > know. Never know when I will want to start avoiding Gmail :) > Ah, *desktop* client! Hm. I actually can't advise there; since I'm constantly mobile, I use webmail for everything - installed Squirrel Mail and RoundCube on my server for remote access. Neither does threading though afaik; nor does PMMail (which is a desktop client). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
RE: Suggested coding style
>> Please do. Bonus points if it handles threading in a Gmail-like style. >> > >May I suggest Gmail? It handles threading in a very Gmail-like style. Curses, foiled by my lack of specificity! I meant desktop client. Although...if another website does similar threading it would be good to know. Never know when I will want to start avoiding Gmail :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
On Sat, Oct 1, 2011 at 2:06 AM, Prasad, Ramit wrote: >>May I suggest a[n] email client that can group mailing list threads? > > Please do. Bonus points if it handles threading in a Gmail-like style. > May I suggest Gmail? It handles threading in a very Gmail-like style. ChrisA running and ducking -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Sep 30, 9:41 pm, Chris Angelico wrote: > On Sat, Oct 1, 2011 at 2:38 AM, Dennis Lee Bieber > wrote: > > > And I would argue that by starting with "Look out your window..." > > you have explicitly excluded the rest of the world from consideration in > > answering; you have narrowed the focus to only the region visible from > > "my window". > > But what if I'm a great windowing magnate, owning windows all over the world? > > (Is anyone else amused by this thread and its ridiculosity?) > > ChrisA Not more ridiculous than people getting religious over not just about silly (man-made) languages but even over the editors they use -- http://mail.python.org/mailman/listinfo/python-list
RE: [OT] Off-Topic Posts and Threads on the Python Mailing List
>I didn't say it would be on-topic. But we don't cease to be well-rounded >human beings with concerns beyond the narrow world of Python programming >just because we are writing on a programming forum. Everything is on topic to programmers! To (mis)quote Sheldon Cooper: "I'm a [programmer]. I have a working knowledge of the entire universe and everything it contains." Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: Suggested coding style
>May I suggest a[n] email client that can group mailing list threads? Please do. Bonus points if it handles threading in a Gmail-like style. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -Original Message- From: python-list-bounces+ramit.prasad=jpmorgan@python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of Devin Jeanpierre Sent: Thursday, September 29, 2011 6:07 PM To: rantingrick Cc: python-list@python.org Subject: Re: Suggested coding style > However, as you use the new format method you will come to appreciate > it. It's an adult beverage with an acquired taste. ;-) Yeah. It's a much more difficult to read thing, but once you learn how to write it it flows faster. Of course, I never managed to learn how to write it... I would suggest that rather than being "complicated" it is "dense". > PS: Has anyone noticed all the off topic chatter about religion and > feelings? Since the main subject of this thread is about zfill i can't > help but wonder if the minions where sent out to present a distraction > with "scripted" pseudo arguments. Just an observation. Devin On Thu, Sep 29, 2011 at 6:56 PM, rantingrick wrote: > On Sep 29, 5:12 pm, Ian Kelly wrote: >> On Thu, Sep 29, 2011 at 6:23 AM, rantingrick wrote: >> > A specific method for padding a string with ONLY zeros is ludicrous >> > and exposes the narrow mindedness of the creator. The only thing worse >> > than "zfill" as a string method is making zfill into built-in >> > function! The ONLY proper place for zfill is as an option in the >> > str.format() method. >> >> > py> "{0:zf10}".format(1234) -> "001234" >> >> Agree that zfill seems to be redundant with str.format, although your >> suggested syntax is atrocious, especially since a syntax already >> exists that fits better in the already-complicated format specifier >> syntax. > > It's interesting that you find the format specifier "complicated". I > will admit that upon first glance i lamented the new format method > spec and attempted to cling to the old string interpolation crap. > However, as you use the new format method you will come to appreciate > it. It's an adult beverage with an acquired taste. ;-) > > One thing that may help format noobs is to look at the spec as two > parts; the part before the colon and the part after the colon. If you > break it down in this manner the meaning starts to shine through. I > will agree, it is a lot of cryptic info squeezed into a small space > HOWEVER you would no want a verbose format specification. > > But i wholeheartedly agree with you points and i would say the zfill > method has no future uses in the stdlib except for historical reasons. > We should deprecate it now. > > >> "{0:=010d}".format(1234) -> "001234" >> >> There are a couple of warts with the existing implementation, however: >> >> 1) str.zfill() operates on strings; the .format() syntax operates on >> numeric types. I would suggest that the "=" fill alignment in format >> specifiers should be extended to do the same thing as zfill when given >> a string. > > EXACTLY! > > PS: Has anyone noticed all the off topic chatter about religion and > feelings? Since the main subject of this thread is about zfill i can't > help but wonder if the minions where sent out to present a distraction > with "scripted" pseudo arguments. Just an observation. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Simplest way to resize an image-like array
Hi folks, I have 500 x 500 arrays of floats, representing 2D "grayscale" images, that I need to resample at a lower spatial resolution, say, 120 x 120 (details to follow, if you feel they are relevant). I've got the numpy, and scipy, and matplotlib. All of these packages hint at the fact that they have the capability to resample an image- like array. But after reading the documentation for all of these packages, none of them make it straightforward, which surprises me. For example, there are several spline and interpolation methods in scipy.interpolate. They seem to return interpolator classes rather than arrays. Is there no simple method which then calls the interpolator, and builds the resampled array? Yes, I can do this myself if I must -- but over the years, I've come to learn that a lot of the code I want is already written, and that sometimes I just have to know where to look for it. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Motion Tracking with Python
On 30-9-2011 4:16, Derek Simkowiak wrote: > Hello, > I have a neat Python project I'd like to share. It does real-time motion > tracking, using > the Python bindings to the OpenCV library: > > http://derek.simkowiak.net/motion-tracking-with-python/ > > There is a YouTube video showing the script in action. > > It's especially neat because my daughter and I worked together on this > project. We used > it to track her two pet gerbils, as part of her science fair project. She > wrote her own > (separate) Python script to read the motion tracking log files, compute > distance and > velocity, and then export those values in a CSV file. Like I say on the web > page: "I’m > convinced that Python is the best language currently available for teaching > kids how to > program." Wow. Very impressive and very enjoyable to read about it. How was her project received at school? Thanks a lot for sharing this. Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Sat, Oct 1, 2011 at 2:38 AM, Dennis Lee Bieber wrote: > And I would argue that by starting with "Look out your window..." > you have explicitly excluded the rest of the world from consideration in > answering; you have narrowed the focus to only the region visible from > "my window". > But what if I'm a great windowing magnate, owning windows all over the world? (Is anyone else amused by this thread and its ridiculosity?) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Fri, Sep 30, 2011 at 09:22:59AM -0700, rusi wrote: > On Sep 30, 8:58 pm, Neil Cerutti wrote: > > On 2011-09-30, DevPlayer wrote: > > > > > > > > > I still assert that contradiction is caused by narrow perspective. > > > > > By that I mean: just because an objects scope may not see a certain > > > condition, doesn't mean that condition is non-existant. > > > > > I also propose that just because something seems to contradict doesn't > > > mean it is false. Take for instance: > > > > > Look out your window. Is it daylight or night time? You may say > > > it is daylight or you may say it is night time. I would > > > disagree that only one of those conditions are true. Both > > > conditions are true. Always. It is only day (or night) for YOU. > > > But the opposite DOES in fact exist on the other side of the > > > world at the same time. > > > > > I call this Duality of Nature (and I believe there was some > > > religion somewhere in some time that has the same notion, > > > Budism I think but I could be mistaken). I see such > > > "contradictions" in what appears to be most truths. > > > > You are not alone. Many ancient philosophers, fathers of > > religious and scientific thought, thought the same. > > > > They thought that contradictory qualities could exist in objects > > simultaneously. For example, they thought that a cat was both big > > and small, because it was big compared to a mouse and small > > compared to a house. They didn't notice that big and small were > > not poperties of the cat, at all but were instead statements > > about how a cat relates to another object. > > > > When you say, "It is night," you are making an assertion about a > > position on the surface of the earth and its relationship to the > > sun. > > > > If you are not discussing a specific a position on the Earth, > > then you cannot make a meaningful assertion about night or day at > > all. Night and Day are not qualities of the entire Earth, but > > only of positions on the Earth. > > But just imagine that we were all pre-galiliean savages -- knowing > nothing about the roundness of the earth, the earth going round and so > on and somehow you and I get on the phone and we start arguing: > Rusi: Its 9:30 pm > Neil: No its 12 noon > > How many cases are there? > We both may be right, I may be wrong (my watch may have stopped) or we > both etc > > ie conflicting data may get resolved within a larger world view (which > is what devplayer is probably saying). > > Until then it is wiser to assume that that larger world view exists > (and I dont yet know it) > than to assume that since I dont know it it does not exist. > > For me (admittedly an oriental) such agnosticism (literally "I-do-not- > know-ness") is as much a foundation for true religiosity as effective > science I.e. humility? -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Sep 30, 8:58 pm, Neil Cerutti wrote: > On 2011-09-30, DevPlayer wrote: > > > > > I still assert that contradiction is caused by narrow perspective. > > > By that I mean: just because an objects scope may not see a certain > > condition, doesn't mean that condition is non-existant. > > > I also propose that just because something seems to contradict doesn't > > mean it is false. Take for instance: > > > Look out your window. Is it daylight or night time? You may say > > it is daylight or you may say it is night time. I would > > disagree that only one of those conditions are true. Both > > conditions are true. Always. It is only day (or night) for YOU. > > But the opposite DOES in fact exist on the other side of the > > world at the same time. > > > I call this Duality of Nature (and I believe there was some > > religion somewhere in some time that has the same notion, > > Budism I think but I could be mistaken). I see such > > "contradictions" in what appears to be most truths. > > You are not alone. Many ancient philosophers, fathers of > religious and scientific thought, thought the same. > > They thought that contradictory qualities could exist in objects > simultaneously. For example, they thought that a cat was both big > and small, because it was big compared to a mouse and small > compared to a house. They didn't notice that big and small were > not poperties of the cat, at all but were instead statements > about how a cat relates to another object. > > When you say, "It is night," you are making an assertion about a > position on the surface of the earth and its relationship to the > sun. > > If you are not discussing a specific a position on the Earth, > then you cannot make a meaningful assertion about night or day at > all. Night and Day are not qualities of the entire Earth, but > only of positions on the Earth. But just imagine that we were all pre-galiliean savages -- knowing nothing about the roundness of the earth, the earth going round and so on and somehow you and I get on the phone and we start arguing: Rusi: Its 9:30 pm Neil: No its 12 noon How many cases are there? We both may be right, I may be wrong (my watch may have stopped) or we both etc ie conflicting data may get resolved within a larger world view (which is what devplayer is probably saying). Until then it is wiser to assume that that larger world view exists (and I dont yet know it) than to assume that since I dont know it it does not exist. For me (admittedly an oriental) such agnosticism (literally "I-do-not- know-ness") is as much a foundation for true religiosity as effective science. -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On 2011-09-30, DevPlayer wrote: > I still assert that contradiction is caused by narrow perspective. > > By that I mean: just because an objects scope may not see a certain > condition, doesn't mean that condition is non-existant. > > I also propose that just because something seems to contradict doesn't > mean it is false. Take for instance: > > Look out your window. Is it daylight or night time? You may say > it is daylight or you may say it is night time. I would > disagree that only one of those conditions are true. Both > conditions are true. Always. It is only day (or night) for YOU. > But the opposite DOES in fact exist on the other side of the > world at the same time. > > I call this Duality of Nature (and I believe there was some > religion somewhere in some time that has the same notion, > Budism I think but I could be mistaken). I see such > "contradictions" in what appears to be most truths. You are not alone. Many ancient philosophers, fathers of religious and scientific thought, thought the same. They thought that contradictory qualities could exist in objects simultaneously. For example, they thought that a cat was both big and small, because it was big compared to a mouse and small compared to a house. They didn't notice that big and small were not poperties of the cat, at all but were instead statements about how a cat relates to another object. When you say, "It is night," you are making an assertion about a position on the surface of the earth and its relationship to the sun. If you are not discussing a specific a position on the Earth, then you cannot make a meaningful assertion about night or day at all. Night and Day are not qualities of the entire Earth, but only of positions on the Earth. -- Neil Cerutti "A politician is an arse upon which everyone has sat except a man." e. e. cummings -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python 2.6.7 on Windows
On Sep 29, 2:59 am, rantingrick wrote: > On Sep 27, 11:25 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote: > > The Python development team is relatively small and chronically busy: too > > much to do and not enough time to do it. > > If that is the case then why do they snub their noses at anyone who > wishes to help? What kind of people would chase off good help just to > save ego? I imagine the folks at py dev sort of like a dying man in > need of a heart transplant; the man informs the doctor that he would > happy to get a transplant but not if the heart came from a jew, asian, > african, latin, russian, or canuck. For the uninitiated, rr is to Python what King Herod was to baby sitting. (With apologies to Tommy Docherty) -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
I still assert that contradiction is caused by narrow perspective. By that I mean: just because an objects scope may not see a certain condition, doesn't mean that condition is non-existant. I also propose that just because something seems to contradict doesn't mean it is false. Take for instance: Look out your window. Is it daylight or night time? You may say it is daylight or you may say it is night time. I would disagree that only one of those conditions are true. Both conditions are true. Always. It is only day (or night) for YOU. But the opposite DOES in fact exist on the other side of the world at the same time. I call this Duality of Nature (and I believe there was some religion somewhere in some time that has the same notion, Budism I think but I could be mistaken). I see such "contradictions" in what appears to be most truths. If I am correct; not sure here; but I think that is part of the new math Choas theory. (The notion that not all variables are known and the results of well defined functions may result in completely different actual outcomes) [Missing variables in such data sets and functions, to me is basically a narrow(er) perspective of the all the revelent factors for such computations.] You could think of this in terms of classes and attributes if you want. Just because an object does not see an attribute, like "has_ connection", doesn't mean the app doesn't have a connection to the server, just that that object doesn't have access to the existance of that attribute, because it is not in scope (ie narrow perspective). I propose that if something seems to contradict itself, that that doesnt' invalidate its value outright. It -could- invalidate its value, but doesn't guarentee no value. How this matters to coding style? No connection visible. It's just a proposed notion. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
On Fri, Sep 30, 2011 at 11:54 PM, rantingrick wrote: > Well "alex", like yourself, i hold expertise in many fields BESIDES > programming. One of which being psychology. > I *knew* it! We're all part of a huge experiment to see how much the human psyche can withstand. If we succeed on the Rick test, do we "level up" and get a second troll to deal with, or is this MST3K-style eternity? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
Note: I am quoting "Passiday" to get this thread back on subject however my reply is for "alex23" the philosopher" On Sep 29, 9:50 pm, alex23 wrote: > On Sep 29, 10:23 pm, rantingrick wrote: > > > What is so bad about breaking code in obscure places? > > Try coding in PHP across minor release versions and see how you feel > about deprecating core functions on a whim. I never said we should remove it now, i said we should deprecate it now. > > We changed print > > to a function which broke just about every piece of code every written > > in this language. > > In a well declared _break_ with backwards compatibility. Not on a whim > between minor releases. Please Google deprecate. > > What is so bad then about breaking some very obscure code? > > Because while you say "some very obscure code", what you really mean > is "code that isn't mine". Well "alex" i can't see a mob approaching with pitchforks because we deprecate a misplaced and rarely used functionality of the stdlib. > As you have no access > to the inner states of _any_ of the people you regularly condemn here > with your hypocritical attacks, I've no idea why you consider yourself > to be an expert on their desires and opinions. Well "alex", like yourself, i hold expertise in many fields BESIDES programming. One of which being psychology. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
On Sep 29, 11:49 pm, Ian Kelly wrote: > Nope, that doesn't work. > > >>> "{0:0>10}".format("-1234") > > '0-1234' > > The whole point of zfill is that it handles signs correctly. py> "{0:-010d}".format(-1234) '-01234' My point was: Use the {char}{repeat}d format for integers and the {char}{<|>|=}{repeat} for strings. Problem solved. No more need for zfill. py> "{0:0>10}".format(-1234) '0-1234' What result would you expect from that string argument? I think it behaves as anyone would expect. If you have a str and you want it interpreted as a negative integer then cast it. py> "{0:010d}".format(int("-1234")) '-01234' If you would like for the spec to handle the case of integers and strings transparently then you need to lobby to have the API changed. Maybe they could add a !i like the !s and !r which would be explicit. However, i don't think implicit coercion of strings to integers is a good idea. Using the int function or !i removes and ambiguities. For me, the spec works just fine as is. -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
from attitude import humour Funny. url link to gif. Funny. Youtube video. Funny. True Pythonees do not speak in English they speak in Python. Shame, this discussion will be sent to the Pearly gates or the Flaming Iron Bars in 5 days. Well, not so much a shame. -- http://mail.python.org/mailman/listinfo/python-list
Re: Motion Tracking with Python
On Thursday 29 September 2011 21:16:52 you wrote: > Hello, > I have a neat Python project I'd like to share. It does real-time motion > tracking, using the Python bindings to the OpenCV library: > > http://derek.simkowiak.net/motion-tracking-with-python/ > > There is a YouTube video showing the script in action. > > It's especially neat because my daughter and I worked together on this > project. We used it to track her two pet gerbils, as part of her science > fair project. She wrote her own (separate) Python script to read the > motion tracking log files, compute distance and velocity, and then > export those values in a CSV file. Like I say on the web page: "I’m > convinced that Python is the best language currently available for > teaching kids how to program." > > I also use Python professionally, and it's worked out great every time. > There's no job Python can't handle. > > > Thanks, > Derek Simkowiak > http://derek.simkowiak.net Hi, this is awesome!! I'm currently working in something similar, but I am having problems with getting data from the CCD (basically i don't know how to do it :), can you give me a tip for doing this? Or explain how you did it please? I not a newbie at python but not as experienced as evidently you are. Thanks a lot in advance. -- (...)Also, since that same law states that any system able to prove its consistency to itself must be inconsistent; any mind that believes it can prove its own sanity is, therefore, insane.(...) Kurt Gödel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Sep 29, 10:05 pm, alex23 wrote: > On Sep 30, 9:37 am, MRAB wrote: > > alex23: > > """And like the Bible, the Zen was created by humans as a joke. If you're > > taking it too seriously, that's your problem.""" > > Strangely, calling the bible self-contradictory wasn't seen as > inflammatory... For the same reason that telling the truth is not slander. The fact is that the Bible IS contradictory with itself. However, your opinion unlike my facts, were full of vile hatred. Nice try attempting to shift the mob against me. -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp compilation error
2011/9/30 Ovidiu Deac : > This is only part of a regex taken from an old perl application which > we are trying to understand/port to our new Python implementation. > > The original regex was considerably more complex and it didn't compile > in python so I removed all the parts I could in order to isolate the > problem such that I can ask help here. > > So the problem is that this regex doesn't compile. On the other hand > I'm not really sure it should. It's an anchor on which you apply *. > I'm not sure if this is legal. > > On the other hand if I remove one of the * it compiles. > re.compile(r"""^(?: [^y]* )*""", re.X) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/re.py", line 190, in compile > return _compile(pattern, flags) > File "/usr/lib/python2.6/re.py", line 245, in _compile > raise error, v # invalid expression > sre_constants.error: nothing to repeat re.compile(r"""^(?: [^y] )*""", re.X) > <_sre.SRE_Pattern object at 0x7f4069cc36b0> re.compile(r"""^(?: [^y]* )""", re.X) > <_sre.SRE_Pattern object at 0x7f4069cc3730> > > Is this a bug in python regex engine? Or maybe some incompatibility with Perl? > > On Fri, Sep 30, 2011 at 12:29 PM, Chris Angelico wrote: >> On Fri, Sep 30, 2011 at 7:26 PM, Ovidiu Deac wrote: >>> $ python --version >>> Python 2.6.6 >> >> Ah, I think I was misinterpreting the traceback. You do actually have >> a useful message there; it's the same error that my Py3.2 produced: >> >> sre_constants.error: nothing to repeat >> >> I'm not sure what your regex is trying to do, but the problem seems to >> be connected with the * at the end of the pattern. >> >> ChrisA >> -- I believe, this is a limitation of the builtin re engine concerning nested infinite quantifiers - (...*)* - in your pattern. You can try a more powerful recent regex implementation, which appears to handle it: http://pypi.python.org/pypi/regex using the VERBOSE flag - re.X all (unescaped) whitespace outside of character classes is ignored, http://docs.python.org/library/re.html#re.VERBOSE the pattern should be equivalent to: r"^(?:[^y]*)*" ie. you are not actually gaining anything with double quantifier, as there isn't anything "real" in the pattern outside [^y]* It appears, that you have oversimplified the pattern (if it had worked in the original app), however, you may simply try with import regex as re and see, if it helps. Cf: >>> >>> regex.findall(r"""^(?: [^y]* )*""", "a bcd e", re.X) ['a bcd e'] >>> re.findall(r"""^(?: [^y]* )*""", "a bcd e", re.X) Traceback (most recent call last): File "", line 1, in File "re.pyc", line 177, in findall File "re.pyc", line 244, in _compile error: nothing to repeat >>> >>> re.findall(r"^(?:[^y]*)*", "a bcd e") Traceback (most recent call last): File "", line 1, in File "re.pyc", line 177, in findall File "re.pyc", line 244, in _compile error: nothing to repeat >>> regex.findall(r"^(?:[^y]*)*", "a bcd e") ['a bcd e'] >>> regex.findall(r"^[^y]*", "a bcd e") ['a bcd e'] >>> hth, vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Benefit and belief
> If you are more upset at my describing the Catholic Church as protecting > child molesters than you are at the Church for actually protecting child > molesters I'm not, and your rhetoric is ridiculous. Devin On Thu, Sep 29, 2011 at 11:10 PM, Steven D'Aprano wrote: > Devin Jeanpierre wrote: > >> I also didn't reprimand anyone, except maybe Steven. > > If you are more upset at my describing the Catholic Church as protecting > child molesters than you are at the Church for actually protecting child > molesters, then your priorities are completely screwed up and your > reprimand means less than nothing to me. I wear it as a badge of honour. > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
parse xml
please click the http://www.secinfo.com/d14qfp.q9j.htm then ,click the following: 44: XML IDEA: Condensed Consolidating Statements of Income XML 5.11M (Details)--R158 there is the citigroup's annual financial report --statements of income,xml file. how can i get a table of statements of income in python ?-- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On 2011-09-30, Chris Angelico wrote: > On Fri, Sep 30, 2011 at 5:24 PM, rusi wrote: >> "You are right," said Nasrudin after carefully hearing one side. >> "You are right," he said after carefully hearing the other side. >> "But both cannot be right!" said the court clerk bewildered. >> After profound thought said the Mulla: >> >> ?"You are right" >> > > And I am right, and you are right, and all is right as right can be! > -- Pish-Tush, a Japanese nobleman in service of /The Mikado/ Never has being right, proper and correct been so thoroughly celebrated. Except perhaps when my C++ program compiles without warnings. That's pretty good, too. -- Neil Cerutti "A politician is an arse upon which everyone has sat except a man." e. e. cummings -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp compilation error
On 30/09/11 11:10:48, Ovidiu Deac wrote: I have the following regexp which fails to compile. Can somebody explain why? re.compile(r"""^(?: [^y]* )*""", re.X) [...] sre_constants.error: nothing to repeat Is this a bug or a feature? A feature: the message explains why this pattern is not allowed. The sub-pattern (?: [^y]* ) matches zero or more non-'y's, so it potentially matches the empty string. It you were allowed to apply '*' to such a sub-pattern, the matcher could go into an infinite loop, finding billions of matching empty strings, one after the other. I'm not sure what you are trying to match, but for zero-or-more not-'y's, you could write r"^[^y]*". This is guaranteed to always match, since there are always at least zero of them. You might as well write r"^", that is also guaranteed to always match. What are you trying to achieve? -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp compilation error
Ovidiu Deac wrote: re.compile(r"""^(?: [^y]* )*""", re.X) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/re.py", line 190, in compile > return _compile(pattern, flags) > File "/usr/lib/python2.6/re.py", line 245, in _compile > raise error, v # invalid expression > sre_constants.error: nothing to repeat re.compile(r"""^(?: [^y] )*""", re.X) > <_sre.SRE_Pattern object at 0x7f4069cc36b0> re.compile(r"""^(?: [^y]* )""", re.X) > <_sre.SRE_Pattern object at 0x7f4069cc3730> > > Is this a bug in python regex engine? Or maybe some incompatibility with > Perl? Before asking whether it is a bug, perhaps you should consider what (if anything) that regex is supposed to actually do. Perhaps you should post the Perl equivalent, and some examples of it in use. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp compilation error
This is only part of a regex taken from an old perl application which we are trying to understand/port to our new Python implementation. The original regex was considerably more complex and it didn't compile in python so I removed all the parts I could in order to isolate the problem such that I can ask help here. So the problem is that this regex doesn't compile. On the other hand I'm not really sure it should. It's an anchor on which you apply *. I'm not sure if this is legal. On the other hand if I remove one of the * it compiles. >>> re.compile(r"""^(?: [^y]* )*""", re.X) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile return _compile(pattern, flags) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat >>> re.compile(r"""^(?: [^y] )*""", re.X) <_sre.SRE_Pattern object at 0x7f4069cc36b0> >>> re.compile(r"""^(?: [^y]* )""", re.X) <_sre.SRE_Pattern object at 0x7f4069cc3730> Is this a bug in python regex engine? Or maybe some incompatibility with Perl? On Fri, Sep 30, 2011 at 12:29 PM, Chris Angelico wrote: > On Fri, Sep 30, 2011 at 7:26 PM, Ovidiu Deac wrote: >> $ python --version >> Python 2.6.6 > > Ah, I think I was misinterpreting the traceback. You do actually have > a useful message there; it's the same error that my Py3.2 produced: > > sre_constants.error: nothing to repeat > > I'm not sure what your regex is trying to do, but the problem seems to > be connected with the * at the end of the pattern. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
回复: how to run in xp?
the command : 2to3-3.2 getcode3.py -w can run in linux it can't run in window xp,can i make it in window xp? -- 原始邮件 -- 发件人: "1248283536"<1248283...@qq.com>; 发送时间: 2011年9月28日(星期三) 晚上7:50 收件人: "Peter Otten"<__pete...@web.de>; "python-list"; 主题: Re: how to run in xp? it can run ,but there is still a problem ,nothing in my file. please run the code in xp+python32 import urllib.request, urllib.parse, urllib.error exchange=['NASDAQ','NYSE','AMEX'] for down in exchange: url='http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange='+down+'&render=download' file=urllib.request.urlopen(url).read() print (file) what you get is: >>> b'' b'' b'' >>> how to fix it? -- Original -- From: "Peter Otten"<__pete...@web.de>; Date: Wed, Sep 28, 2011 04:04 PM To: "python-list"; Subject: Re: how to run in xp? =?gbk?B?ytjW6rT9zcM=?= wrote: > #coding:utf-8 > import urllib > exchange=['NASDAQ','NYSE','AMEX'] > for down in exchange: > myfile=open('./'+down,'w') > url='http://www.nasdaq.com/screening/companies- \ > by-industry.aspx?exchange='+down+'&render=download' > file=urllib.urlopen(url).read() myfile.write(file) > print ('ok',down) > myfile.close() > > it can run in ubuntu+python2.6 ,when it run in window xp+python32,the > output is Traceback (most recent call last): > File "C:\Python32\getcode.py", line 8, in > file=urllib.urlopen(url).read() > AttributeError: 'module' object has no attribute 'urlopen' > > i change it into: > #coding:utf-8 > import urllib.request > exchange=['NASDAQ','NYSE','AMEX'] > for down in exchange: > myfile=open('./'+down,'w') > url='http://www.nasdaq.com/screening/companies-by- industry.aspx?exchange='+down+'&render=download' > file=urllib.request.urlopen(url).read() > myfile.write(file) > print ('ok',down) > myfile.close() > > the output is : > Traceback (most recent call last): > File "C:\Python32\getcode.py", line 9, in > myfile.write(file) > TypeError: must be str, not bytes > > how to make it run in xp+python32? The problem here is the switch from Python 2 to 3. Python 3 has some backwards-incompatible Syntax changes along with changes to classes and library organisation. The good news is that there's a tool, 2to3, that can handle most of these changes: $ cat getcode.py #coding:utf-8 import urllib exchange=['NASDAQ','NYSE','AMEX'] for down in exchange: myfile=open('./'+down,'wb') url='http://www.nasdaq.com/screening/companies-by- industry.aspx?exchange='+down+'&render=download' file=urllib.urlopen(url).read() myfile.write(file) print 'ok', down myfile.close() $ cp getcode.py getcode3.py $ 2to3-3.2 getcode3.py -w RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: Refactored getcode3.py --- getcode3.py (original) +++ getcode3.py (refactored) @@ -1,10 +1,10 @@ #coding:utf-8 -import urllib +import urllib.request, urllib.parse, urllib.error exchange=['NASDAQ','NYSE','AMEX'] for down in exchange: myfile=open('./'+down,'wb') url='http://www.nasdaq.com/screening/companies-by- industry.aspx?exchange='+down+'&render=download' -file=urllib.urlopen(url).read() +file=urllib.request.urlopen(url).read() myfile.write(file) -print 'ok', down +print('ok', down) myfile.close() RefactoringTool: Files that were modified: RefactoringTool: getcode3.py $ cat getcode3.py #coding:utf-8 import urllib.request, urllib.parse, urllib.error exchange=['NASDAQ','NYSE','AMEX'] for down in exchange: myfile=open('./'+down,'wb') url='http://www.nasdaq.com/screening/companies-by- industry.aspx?exchange='+down+'&render=download' file=urllib.request.urlopen(url).read() myfile.write(file) print('ok', down) myfile.close() $ python3.2 getcode3.py ok NASDAQ ok NYSE ok AMEX -- http://mail.python.org/mailman/listinfo/python-list-- http://mail.python.org/mailman/listinfo/python-list
Re: regexp compilation error
On Fri, Sep 30, 2011 at 7:26 PM, Ovidiu Deac wrote: > $ python --version > Python 2.6.6 Ah, I think I was misinterpreting the traceback. You do actually have a useful message there; it's the same error that my Py3.2 produced: sre_constants.error: nothing to repeat I'm not sure what your regex is trying to do, but the problem seems to be connected with the * at the end of the pattern. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp compilation error
$ python --version Python 2.6.6 On Fri, Sep 30, 2011 at 12:18 PM, Chris Angelico wrote: > On Fri, Sep 30, 2011 at 7:10 PM, Ovidiu Deac wrote: >> I have the following regexp which fails to compile. Can somebody explain why? >> > re.compile(r"""^(?: [^y]* )*""", re.X) >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python2.6/re.py", line 190, in compile >> return _compile(pattern, flags) >> File "/usr/lib/python2.6/re.py", line 245, in _compile >> raise error, v # invalid expression >> sre_constants.error: nothing to repeat >> >> Is this a bug or a feature? > > What version of Python are you using? It looks like you're running in > a Python 3 interpreter, and loading a Python 2 module (as shown by the > python2.6 in the path and the Python 2 error-raise syntax). You may > have a problem with your module path. > > Running that line of code in Python 3.2 for Windows produces this error: > re.compile(r"""^(?: [^y]* )*""", re.X) > Traceback (most recent call last): > File "", line 1, in > re.compile(r"""^(?: [^y]* )*""", re.X) > File "C:\Python32\lib\re.py", line 206, in compile > return _compile(pattern, flags) > File "C:\Python32\lib\re.py", line 256, in _compile > return _compile_typed(type(pattern), pattern, flags) > File "C:\Python32\lib\functools.py", line 180, in wrapper > result = user_function(*args, **kwds) > File "C:\Python32\lib\re.py", line 268, in _compile_typed > return sre_compile.compile(pattern, flags) > File "C:\Python32\lib\sre_compile.py", line 495, in compile > code = _code(p, flags) > File "C:\Python32\lib\sre_compile.py", line 480, in _code > _compile(code, p.data, flags) > File "C:\Python32\lib\sre_compile.py", line 74, in _compile > elif _simple(av) and op is not REPEAT: > File "C:\Python32\lib\sre_compile.py", line 359, in _simple > raise error("nothing to repeat") > sre_constants.error: nothing to repeat > > Does that help at all? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: regexp compilation error
On Fri, Sep 30, 2011 at 7:10 PM, Ovidiu Deac wrote: > I have the following regexp which fails to compile. Can somebody explain why? > re.compile(r"""^(?: [^y]* )*""", re.X) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/re.py", line 190, in compile > return _compile(pattern, flags) > File "/usr/lib/python2.6/re.py", line 245, in _compile > raise error, v # invalid expression > sre_constants.error: nothing to repeat > > Is this a bug or a feature? What version of Python are you using? It looks like you're running in a Python 3 interpreter, and loading a Python 2 module (as shown by the python2.6 in the path and the Python 2 error-raise syntax). You may have a problem with your module path. Running that line of code in Python 3.2 for Windows produces this error: >>> re.compile(r"""^(?: [^y]* )*""", re.X) Traceback (most recent call last): File "", line 1, in re.compile(r"""^(?: [^y]* )*""", re.X) File "C:\Python32\lib\re.py", line 206, in compile return _compile(pattern, flags) File "C:\Python32\lib\re.py", line 256, in _compile return _compile_typed(type(pattern), pattern, flags) File "C:\Python32\lib\functools.py", line 180, in wrapper result = user_function(*args, **kwds) File "C:\Python32\lib\re.py", line 268, in _compile_typed return sre_compile.compile(pattern, flags) File "C:\Python32\lib\sre_compile.py", line 495, in compile code = _code(p, flags) File "C:\Python32\lib\sre_compile.py", line 480, in _code _compile(code, p.data, flags) File "C:\Python32\lib\sre_compile.py", line 74, in _compile elif _simple(av) and op is not REPEAT: File "C:\Python32\lib\sre_compile.py", line 359, in _simple raise error("nothing to repeat") sre_constants.error: nothing to repeat Does that help at all? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Counting the number of call of a function
The keys of globals() are the _names_. You're giving it the function itself. Ow, ok. I didn't caught it. I understand now. > A decorator would be better. Yes. I keep the solution with foo=Wraper(foo) Thanks a lot all ! Laurent -- http://mail.python.org/mailman/listinfo/python-list
regexp compilation error
I have the following regexp which fails to compile. Can somebody explain why? >>> re.compile(r"""^(?: [^y]* )*""", re.X) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 190, in compile return _compile(pattern, flags) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat Is this a bug or a feature? Thanks, Ovidiu -- http://mail.python.org/mailman/listinfo/python-list
Re: Motion Tracking with Python
On Fri, Sep 30, 2011 at 4:39 PM, alex23 wrote: >> or writing a MS Word virus in Python... > > Now that's just crazy talk. > ... and I thought all three were. You know what they say - truth is stranger than fiction, because fiction has to make sense! Although the device driver example you cite is still ring-3 code, and the Linux kernel is still in C. I like the idea of a special OS written in Python though; it wouldn't be Linux, but it could well be an excellent embedded-device OS. It'd probably end up having to reinvent all sorts of facilities like process isolation and such, though. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Fri, Sep 30, 2011 at 5:24 PM, rusi wrote: > "You are right," said Nasrudin after carefully hearing one side. > "You are right," he said after carefully hearing the other side. > "But both cannot be right!" said the court clerk bewildered. > After profound thought said the Mulla: > > "You are right" > And I am right, and you are right, and all is right as right can be! -- Pish-Tush, a Japanese nobleman in service of /The Mikado/ Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: Benefit and belief
On Sep 30, 4:03 am, Devin Jeanpierre wrote: > > But anyway, no, we don't agree on what it means to be friendly or what > a hostile atmosphere is. I've noticed that people tend to be a lot > harsher here than what I'm used to, so perhaps your attitude to it is > more common on mailing-lists and I should just adapt. A Mulla Nasruddin story comes to mind: The judge in a village court had gone on vacation. Nasrudin was asked to be temporary judge for a day. Mulla sat on the Judge's chair and ordered the first case to be brought up for hearing. "You are right," said Nasrudin after carefully hearing one side. "You are right," he said after carefully hearing the other side. "But both cannot be right!" said the court clerk bewildered. After profound thought said the Mulla: "You are right" -- http://mail.python.org/mailman/listinfo/python-list