Re: How to use imported function to get current globals

2014-06-07 Thread 1989lzhh
thanks all you guys. I have find the solution which is quite simple by using sys._frame(1).f_locals in function to get the caller's scope The following is my user case: I am writing a tool to translate python code to cython code then compiled using decorate. jit, build=make("mymodule") #jit func

Re: OT: This Swift thing

2014-06-07 Thread Marko Rauhamaa
Roy Smith : > The original MacOS was written in Pascal (both applications and > kernel). Being able to touch memory locations or registers requires no > more than a few short glue routines written in assembler. Pascal is essentially equivalent to C, except Pascal has a cleaner syntax. I like the

Re: Python 3.2 has some deadly infection

2014-06-07 Thread rurpy
On 06/05/2014 05:02 PM, Steven D'Aprano wrote: >[...] > But Linux Unicode support is much better than Windows. Unicode support in > Windows is crippled by continued reliance on legacy code pages, and by > the assumption deep inside the Windows APIs that Unicode means "16 bit > characters". See,

Re: try/except/finally

2014-06-07 Thread Rustom Mody
On Sunday, June 8, 2014 5:17:21 AM UTC+5:30, Chris Angelico wrote: > On Sun, Jun 8, 2014 at 8:49 AM, Ethan Furman wrote: > > I don't remember if I almost had this in real code or if I learned about it > > first, but it can definitely be a gotcha. It seems to me that if the try > > block exits with

Re: OT: This Swift thing

2014-06-07 Thread Steven D'Aprano
On Sat, 07 Jun 2014 20:09:37 -0400, Roy Smith wrote: > We've also got machines that are so fast, it's not longer critical that > we squeeze out every last iota of performance. Oh, but wait, now we're > trying to do absurd things like play full-motion video games on phones, > where efficiency equa

Re:try/except/finally

2014-06-07 Thread Dave Angel
Frank B Wrote in message: > Ok; this is a bit esoteric. > > So finally is executed regardless of whether an exception occurs, so states > the docs. > > But, I thought, if I from my function first, that should take > precedence. > > au contraire > > Turns out that if you do this: > > try: >

Re:How to use imported function to get current globals

2014-06-07 Thread Dave Angel
1989lzhh <1989l...@gmail.com> Wrote in message: > Here is the code > m1.py > def f(): > print globals() > > m2.py > from m1 import f > f()# how to get current module's globals? > As others have said, it's probably a bad idea. I can think of 3 reasons to try: teacher said so, writing a debu

Re: try/except/finally

2014-06-07 Thread Roy Smith
In article , Mark Lawrence wrote: > On 08/06/2014 01:12, Roy Smith wrote: > > In article , > > Chris Angelico wrote: > > > >> A return statement inside a finally block is code smell. > > > > Not to my nose. It seems like a perfectly reasonable thing to do. > > > > I agree, the code smell is

Re: Uniform Function Call Syntax (UFCS)

2014-06-07 Thread Gregory Ewing
Ian Kelly wrote: It's a nice feature in a statically typed language, but I'm not sure how well it would work in a language as dynamic as Python. Also it doesn't sit well with Python's "one obvious way to do it" guideline, because it means there are *two* equally obvious ways to call a function

Re: OT: This Swift thing

2014-06-07 Thread Gregory Ewing
Dennis Lee Bieber wrote: Not "standard" Pascal... It had pointer types, but no means to "stuff" an integer into the pointer variable in order to dereference it as a memory address... Although most implementations would let you get the same effect by abusing variant records (the equivale

Re: OT: This Swift thing

2014-06-07 Thread Gregory Ewing
Michael Torrie wrote: Technically C doesn't either, except via subroutines in libc, though C does have pointers which would be used to access memory. The Pascal that Apple used had a way of casting an int to a pointer, so you could do all the tricks you can do with pointers in C. -- Greg -- ht

Re: try/except/finally

2014-06-07 Thread Mark Lawrence
On 08/06/2014 01:12, Roy Smith wrote: In article , Chris Angelico wrote: A return statement inside a finally block is code smell. Not to my nose. It seems like a perfectly reasonable thing to do. I agree, the code smell is the return in the except block. -- My fellow Pythonistas, ask

Re: How to use imported function to get current globals

2014-06-07 Thread Chris Angelico
On Sun, Jun 8, 2014 at 10:28 AM, 1989lzhh <1989l...@gmail.com> wrote: > > > 发自我的 iPhone > >> 在 Jun 8, 2014,4:52,Chris Angelico 写道: >> >>> On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh <1989l...@gmail.com> wrote: >>> Here is the code >>> m1.py >>> def f(): >>>print globals() >>> >>> m2.py >>> from m

Re: OT: This Swift thing

2014-06-07 Thread Chris Angelico
On Sun, Jun 8, 2014 at 10:09 AM, Roy Smith wrote: > We've also got machines that are so fast, it's not longer critical that > we squeeze out every last iota of performance. Oh, but wait, now we're > trying to do absurd things like play full-motion video games on phones, > where efficiency equates

Re: How to use imported function to get current globals

2014-06-07 Thread 1989lzhh
发自我的 iPhone > 在 Jun 8, 2014,4:52,Chris Angelico 写道: > >> On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh <1989l...@gmail.com> wrote: >> Here is the code >> m1.py >> def f(): >>print globals() >> >> m2.py >> from m1 import f >> f()# how to get current module's globals? > > As Ian said, you almos

Re: try/except/finally

2014-06-07 Thread Roy Smith
In article , Chris Angelico wrote: > A return statement inside a finally block is code smell. Not to my nose. It seems like a perfectly reasonable thing to do. -- https://mail.python.org/mailman/listinfo/python-list

Re: OT: This Swift thing

2014-06-07 Thread Roy Smith
In article <5393a264$0$29988$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Sat, 07 Jun 2014 14:11:27 -0400, Roy Smith wrote: > > > And, why do you need a library routine to touch a memory location, when > > you can just dereference an integer? :-) > > And in one sentence we

Re: try/except/finally

2014-06-07 Thread Chris Angelico
On Sun, Jun 8, 2014 at 8:49 AM, Ethan Furman wrote: > I don't remember if I almost had this in real code or if I learned about it > first, but it can definitely be a gotcha. It seems to me that if the try > block exits with an explicit return, and then the finally block exits with > an explicit re

Re: OT: This Swift thing

2014-06-07 Thread Steven D'Aprano
On Sat, 07 Jun 2014 14:11:27 -0400, Roy Smith wrote: > And, why do you need a library routine to touch a memory location, when > you can just dereference an integer? :-) And in one sentence we have an explanation for 90% of security vulnerabilities before PHP and SQL injection attacks... C is n

Re: try/except/finally

2014-06-07 Thread Ethan Furman
On 06/06/2014 11:22 AM, Ned Batchelder wrote: On 6/6/14 1:47 PM, Frank B wrote: Ok; thanks for the underscore and clarification. Just need to adjust my thinking a bit. Did this come up in real code? I've seen this point about finally/return semantics a number of times, but haven't seen re

Re: OT: This Swift thing

2014-06-07 Thread Steven D'Aprano
On Sat, 07 Jun 2014 11:13:42 -0400, Dennis Lee Bieber wrote: > About a decade later, said manager retired and confessed that the choice > of Pascal was a mistake There's Pascal and there's Pascal. Standard Pascal, I admit, is woefully unsuitable for real world work. But Pascal with suitable exte

Re: Automating windows media player on win7

2014-06-07 Thread MRAB
On 2014-06-06 14:39, Deogratius Musiige wrote: Thanks a lot mate. You just made my day. I have looked around the net but cannot find the controls available. I would like to be able to: - get current playing track - get wmplayer state (playing/paused/stopped) - get the selected sound device [s

Re: How to use imported function to get current globals

2014-06-07 Thread Ned Batchelder
On 6/7/14 1:40 PM, 1989lzhh wrote: Here is the code m1.py def f(): print globals() m2.py from m1 import f f()# how to get current module's globals? Looking at the code you have posted in your two messages so far, it seems like you are building something very interesting and ambitious.

Re: How to use imported function to get current globals

2014-06-07 Thread Chris Angelico
On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh <1989l...@gmail.com> wrote: > Here is the code > m1.py > def f(): > print globals() > > m2.py > from m1 import f > f()# how to get current module's globals? As Ian said, you almost certainly do not want to do this. But if you have a solid use-case that

Re: os.startfile hanging onto the launched app, or my IDE?

2014-06-07 Thread Tim Golden
On 06/06/2014 21:34, Josh English wrote: I have been using os.startfile(filepath) to launch files I've created in Python, mostly Excel spreadsheets, text files, or PDFs. When I run my script from my IDE, the file opens as I expect. But if I go back to my script and re-run it, the external progra

Re: Uniform Function Call Syntax (UFCS)

2014-06-07 Thread Ian Kelly
On Sat, Jun 7, 2014 at 12:45 AM, jongiddy wrote: > The language D has a feature called Uniform Function Call Syntax, which > allows instance methods to be resolved using function calls. > > In Python terms, the call: > > x.len() > > would first check if 'x' has a method 'len', and would then look

Re: Regarding Python official website

2014-06-07 Thread Kushal Das
On Sat, Jun 7, 2014 at 1:12 AM, Aseem Bansal wrote: > The Python website is undergoing an overhaul for better looks. Is there > anything like a forum where it is being discussed. I mean where the schedule > for this is being maintained or the same is being discussed? https://github.com/python/p

Re: OT: This Swift thing

2014-06-07 Thread Roy Smith
In article , Michael Torrie wrote: > On 06/07/2014 12:11 PM, Roy Smith wrote: > > Several language constructs in C are there specifically to diddle bits > > in hardware. Bit fields were in the earliest implementations of the > > language to allow you to address individual bit control and stat

Re: OT: This Swift thing

2014-06-07 Thread Michael Torrie
On 06/07/2014 12:11 PM, Roy Smith wrote: > Several language constructs in C are there specifically to diddle bits > in hardware. Bit fields were in the earliest implementations of the > language to allow you to address individual bit control and status bits > in memory-mapped device controllers

Token-based authentication (was http.server.BaseHTTPRequestHandler basic auth logout? Django authentication system for REST interface?)

2014-06-07 Thread Demian Brecht
On Jun 6, 2014 6:30 PM, "Roy Smith" wrote: > We would have to keep state on the server side about every extant valid > token (but then again, we need to do that now, for each session). If you didn't want to have to manage such state server side, you could opt to use JWTs (http://datatracker.ietf.

Re: OT: This Swift thing

2014-06-07 Thread Roy Smith
In article , Michael Torrie wrote: > Technically C doesn't [have features to support hitting the hardware] > either, except via subroutines in libc, though C does have pointers > which would be used to access memory. Several language constructs in C are there specifically to diddle bits in h

Re: Regarding Python official website

2014-06-07 Thread Aseem Bansal
The Job board. It has been on hold for quite some time. -- https://mail.python.org/mailman/listinfo/python-list

Re: How to use imported function to get current globals

2014-06-07 Thread Ian Kelly
On Sat, Jun 7, 2014 at 11:40 AM, 1989lzhh <1989l...@gmail.com> wrote: > Here is the code > m1.py > def f(): > print globals() > > m2.py > from m1 import f > f()# how to get current module's globals? Evaluate globals() in the current module and pass the resulting dict in as a parameter: # m1.p

How to use imported function to get current globals

2014-06-07 Thread 1989lzhh
Here is the code m1.py def f(): print globals() m2.py from m1 import f f()# how to get current module's globals? -- https://mail.python.org/mailman/listinfo/python-list

Re: OT: This Swift thing

2014-06-07 Thread Michael Torrie
On 06/07/2014 09:23 AM, Dennis Lee Bieber wrote: > On 07 Jun 2014 04:57:19 GMT, Steven D'Aprano > declaimed the following: > >> >> Swift is intended as a new generation *systems language*. The old >> generation of systems languages are things like C, Objective-C, C#, C++, >> Java, Pascal, Algol

Science in Islam

2014-06-07 Thread bv4bv4bv4
Science in Islam "We (God) shall show them Our signs in the Universe and within themselves, until it becomes clear to them that this is the Truth." Quran 41:53 The Quran, the book of Islam, is the final book of revelation from God to humanity and the last in the line of revelations given to the

Re: OT: This Swift thing

2014-06-07 Thread Roy Smith
In article , Dennis Lee Bieber wrote: > On 07 Jun 2014 04:57:19 GMT, Steven D'Aprano > declaimed the following: > > > > >Swift is intended as a new generation *systems language*. The old > >generation of systems languages are things like C, Objective-C, C#, C++, > >Java, Pascal, Algol, and s

Re: OT: This Swift thing

2014-06-07 Thread Roy Smith
In article , Dennis Lee Bieber wrote: > On Sat, 07 Jun 2014 08:52:36 -0400, Roy Smith declaimed the > following: > > > >You are lucky indeed. Trust me, in big companies, technical decisions > >are often made by people who are not using the technology. > > Or influenced by someone fam

Re: strange behaivor of nested function

2014-06-07 Thread Steven D'Aprano
On Sat, 07 Jun 2014 19:17:23 +0800, 1989lzhh wrote: > here is code > > def make(): > def jit(sig): > def wrap(function): > sig=sig[0] # unbound local error You are saying: "sig is a local variable. Assign sig to the value of sig[0]." But what is sig? You've said it is a

Re: OT: This Swift thing

2014-06-07 Thread Roy Smith
In article <87zjhpm8q7@dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Sturla Molden writes: > > > Alain Ketterlin wrote: > >> Sturla Molden writes: > >> > >>> Alain Ketterlin wrote: > >>> > Many of these students suggest Python as the > development language (they learned i

Re: strange behaivor of nested function

2014-06-07 Thread Chris Angelico
On Sat, Jun 7, 2014 at 9:17 PM, 1989lzhh <1989l...@gmail.com> wrote: > def make(): > def jit(sig): > def wrap(function): > sig=sig[0] # unbound local error, if change to sig='' would be > just fine > return function > return wrap > return jit > jit=m

strange behaivor of nested function

2014-06-07 Thread 1989lzhh
here is code def make(): def jit(sig): def wrap(function): sig=sig[0] # unbound local error, if change to sig='' would be just fine return function return wrap return jit jit=make() @jit('') def f(): pass It is strange that the interpreter com

Re: OT: This Swift thing

2014-06-07 Thread Alain Ketterlin
Mark Lawrence writes: > On 07/06/2014 09:20, Alain Ketterlin wrote: >> Sturla Molden writes: >> Many of these students suggest Python as the >> development language (they learned it and liked it), and the suggestion >> is (almost) always rejected, in favor of Java or C# or C/C++. >>

Re: http.server.BaseHTTPRequestHandler basic auth logout? Django authentication system for REST interface?

2014-06-07 Thread Chris Angelico
On Sat, Jun 7, 2014 at 4:23 PM, dieter wrote: > Dan Stromberg writes: > >> I have some code for a web server. Right now, it uses >> BaseHTTPRequestHandler with Basic Auth, but we want to be able to log >> out, and there doesn't appear to be a general way to log out of >> something using Basic Au

Re: OT: This Swift thing

2014-06-07 Thread Mark Lawrence
On 07/06/2014 09:20, Alain Ketterlin wrote: Sturla Molden writes: Alain Ketterlin wrote: Sturla Molden writes: Alain Ketterlin wrote: Many of these students suggest Python as the development language (they learned it and liked it), and the suggestion is (almost) always rejected, in fav

Re: OT: This Swift thing

2014-06-07 Thread Alain Ketterlin
Sturla Molden writes: > Alain Ketterlin wrote: >> Sturla Molden writes: >> >>> Alain Ketterlin wrote: >>> Many of these students suggest Python as the development language (they learned it and liked it), and the suggestion is (almost) always rejected, in favor of Java or C# or

Re: OT: This Swift thing

2014-06-07 Thread Christian Gollwitzer
Am 06.06.14 13:20, schrieb Alain Ketterlin: Chris Angelico writes: It's impossible to accidentally call a base class's method when you ought to have called the overriding method in the subclass, which is a risk in C++ [2]. I don't how this can happen in C++, unless you actually have an instan