Re: Something confusing about non-greedy reg exp match
On Sep 6, 8:46 pm, "[email protected]" wrote: > If I do this: > > import re > a=re.search(r'hello.*?money', 'hello how are you hello funny money') > > I would expect a.group(0) to be "hello funny money", since .*? is a > non-greedy match. But instead, I get the whole sentence, "hello how > are you hello funny money". > > Is this expected behavior? Yes. search() finds the *first* match. The non-greedy quantifier does not transform search() into a function that finds all possible matches and then picks the shortest one. Instead, the non-greedy quantifier causes search() to return the shortest possible first match (v. the default which is the "longest possible first match"). In your case, there is only one possible first match, so the non-greedy quantifier does nothing. -- http://mail.python.org/mailman/listinfo/python-list
Re: simple string question
"Chris Rebert" wrote in message news:[email protected]... > On Sun, Sep 6, 2009 at 10:29 PM, jwither wrote: >> Given a string (read from a file) which contains raw escape sequences, >> (specifically, slash n), what is the best way to convert that to a parsed >> string, where the escape sequence has been replaced (specifically, by a >> NEWLINE token)? > > There's probably a more general method covering all the escape > sequences, but for just \n: > > your_string = your_string.replace("\\n", "\n") > > Cheers, > Chris > -- > http://blog.rebertia.com Thanks! (the others are more likely to be errors than deliberate anyway) James Withers -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Sep 7, 3:42 pm, sturlamolden wrote:
> On 7 Sep, 07:17, grbgooglefan wrote:
>
> > What is best way to embed python in multi-threaded C++ application?
>
> Did you remeber to acquire the GIL? The GIL is global to the process
> (hence the name).
>
> void foobar(void)
> {
> PyGILState_STATE state = PyGILState_Ensure();
>
> /* Safe to use Python C API here */
>
> PyGILState_Release(state);
You can't use that in this case as they specifically are talking about
a interpreter per thread, which implies creating additional sub
interpreters. The simplified GIL state API you mentioned only works
for threads operating in the main (first) interpreter created within
the process.
The OP can do what they want, but they need to user lower level
routines for creating their own thread state objects and acquiring the
GIL against them.
Graham
--
http://mail.python.org/mailman/listinfo/python-list
Re: Evil trend report - cancelled
On Sep 7, 1:07 pm, John Nagle wrote: > > Accidentally posted a private e-mail. Cancelled. Sorry. > You think you can get out of it that easily? You've exposed yourself as an enemy of the Empire now! You'd better look over your shoulder for guys dressed in black cloaks breathing heavily ... ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Evil trend report
On Sep 6, 4:27 am, Steven D'Aprano wrote: > Why aren't you including Yahoo search in your test? > (It has a much bigger market share than MSN, even > rebranded as Bing). Microsoft acquired Yahoo! at the end of July. I would think Yahoo! search is powered by Bing by now. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Evil trend report
On Sun, 06 Sep 2009 12:35:11 -0700, John Yeung wrote: > On Sep 6, 4:27 am, Steven D'Aprano cybersource.com.au> wrote: >> Why aren't you including Yahoo search in your test? (It has a much >> bigger market share than MSN, even rebranded as Bing). > > Microsoft acquired Yahoo! at the end of July. I would think Yahoo! > search is powered by Bing by now. No they didn't. At the end of July, Microsoft and Yahoo did a deal where Microsoft can get access to Yahoo's search results. If anything, Bing is powered by Yahoo rather than the other way around. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Evil trend report
On 2009-09-06, John Nagle wrote: > Bing >A 32.4% () >A 10.8% (non_commercial) >Q50 40.0% () >Q15 12.0% (no_location) >U 54.0% (no_website) >U33 26.4% (non_commercial) >X 10.8% (negative_info) >X17 13.6% (no_location) > > Google >A 10.8% () >A 43.3% (non_commercial) >Q46 38.3% () >Q20 16.7% (no_location) >Q 10.8% (non_commercial) >U 43.3% (no_website) >U28 23.3% (non_commercial) >X16 13.3% (no_location) > Test complete: Evil trend report I've absolutely no clue what those tables are supposed to represent (well, I do know what Bing and Google are, but beyond that...). > Right now, Google is winning slightly. Winning what? > It changes from minute to minute, because it's based on the > current list of hot search topics from Google. More on this > later. Was there a "part 1" to this post that I missed? -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Sep 7, 2:04 pm, sturlamolden wrote:
> I just showed you how...
Modified the thread function to use these APIs, but the call to
PyGILState_Ensure() is not returning at all.
void *callPyFunction(void * arg)
{
// Method two to get function eval
long thridx=(long)arg;
printf("\n>my num=%d, calling showstr pyfunction\n",thridx);
char callpyf[] = "showstr(100)\n";
PyGILState_STATE state = PyGILState_Ensure();
printf("after PyGILState_Ensure\n");
PyObject* pycall = PyRun_String(callpyf,Py_file_input,glb, loc);
if(pycall == NULL || PyErr_Occurred()){
printf("PyRun_String failed\n");
PyErr_Print();
} else
printf("%d thread called showstr pyfunction ok\n",thridx);
PyGILState_Release(state);
pthread_exit(NULL);
}
--
http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
2009/9/7 Terry Reedy : > Dennis Lee Bieber wrote: >> I'd say the >> mutables are in the majority > > I think it depends on whether one counts classes or instances. Typical > programs have a lot of numbers and strings. Ah, but immutable instances can be, and often are, interned. This will cut down on their number considerably. ;-) -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is "#!/usr/bin/env python" the better shebang line ?
On Sep 6, 10:01 am, Timothy Madden wrote: > Hello > > Sorry if this has been discussed before, my search did not find it. > My questions is if I should use > #!/usr/bin/env python > as the shebang line in a portable and open python script and if it does > help with portability and usage. Note that there is one limitation of /usr/bin/env on many systems: you cannot supply any arguments to the interpreter. e.g. #!/usr/bin/env python -u The above will fail on many systems as env will literally try to find a file named "python -u". http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/237208 Another, more obvious, case where you might avoid /usr/bin/env is when you know (or might expect in the future) that there is another Python version on the system which your script will not work with. Then it's often convenient to hard code the interpreter path. This comes up mostly in environments where you're not the administrator and have another Python version installed in a custom place which you (and any co-developers) have in their PATH. For example, if you wanted to share your script with a non-team member, then having /usr/bin/env in your script would force them to have to change their PATH first. > Then, supposing /usr/bin/env is better than /usr/bin/python and I use > it, is it not the case that many editors and code analysing programs, > that want to know the script language for syntax highlighting, code > completion, tags and source code browsing, etc, will loose their > functionality because of this shebang line ? Is this not a good general > reason to use the old one ? I personally use vim, and it will recognize either shebang, or if none is present (as in a typical importable module) it will notice the file suffix, .py. It's not an issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Application-global "switches"?
kj wrote: > I'm looking for the "best-practice" way to define application-global > read-only switches, settable from the command line. The best > example I can think of of such global switch is the built-in variable > __debug__. This variable is visible everywhere in a program, and > broadly affects its operation. This is what I've done in the past... Create a Config class in a module called config.py and instantiate it class Config: def __init__(self): self.debug = True # etc config = Config() Then where you want to use it you can then use from config import config if config.debug: # blah This has the advantage that you can define some methods on your config object (eg save). I don't know whether this is best practice but it works for me! -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: simple string question
> There's probably a more general method covering all the escape
> sequences, but for just \n:
>
> your_string = your_string.replace("\\n", "\n")
py> s = "hello\\r\\n"
py> s
'hello\\r\\n'
py> s.decode("string_escape")
'hello\r\n'
py>
--
http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Sep 7, 3:41 pm, Graham Dumpleton wrote: > On Sep 7, 3:42 pm, sturlamolden wrote: > interpreters. The simplified GIL state API you mentioned only works > for threads operating in the main (first) interpreter created within > the process. I modified my program to have Py_Initialize and compilation of one Python function done in main() thread. Then I am calling only that function in callPyFunction() thread. But, this thread does not come out of PyGILState_Ensure() function. > The OP can do what they want, but they need to user lower level > routines for creating their own thread state objects and acquiring the > GIL against them. > > Graham What are the "lower level routines" for creating own thread state objects & acquiring GILs. Also, where can I find more information about those routines? Please guide. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: simple string question
On 7 Sep, 07:29, "jwither" wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
>
> James Withers
Others have answered how to replace '\\n' with '\n'. For a more
general approach which will handle all string escape sequences allowed
in python (including '\xdd' and similar), python's eval can be used:
>>> quoted_string = "'hello\\nworld\\x21\\tand\\tgood\\040\\x47ood bye!'"
>>> print quoted_string
'hello\nworld\x21\tAnd\tgood\040\x47ood bye!'
>>> print eval('str(%s)' % quoted_string)
hello
world! And good Good bye!
If the string isn't quoted just enclosed it in quotes first:
>>> unquoted_string = 'hello\\nworld\\x21\\tand\\tgood\\040\\x47ood bye!'
>>> print unquoted_string
hello\nworld\x21\tAnd\tgood\040\x47ood bye!
>>> print eval('str("%s")' % unquoted_string)
hello
world! And good Good bye!
/Niklas Norrthon
--
http://mail.python.org/mailman/listinfo/python-list
Windows binaries of python in debug mode
Hello everyone, I am looking for a version of python 2.5.x compiled for windows in debug mode, but I can't find this, does anyone have a link or have a version that he/she can send me? Thank you, Gabriel -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
John Nagle wrote: In the beginning, strings, tuples, and numbers were immutable, and everything else was mutable. That was simple enough. But over time, Python has acquired more immutable types - immutable sets and immutable byte arrays. Each of these is a special case. Immutability is interesting for threaded programs, because immutable objects can be shared without risk. Consider a programming model where objects shared between threads must be either immutable or "synchronized" in the sense that Java uses the term. Such programs are free of most race conditions, without much programmer effort to make them so. Of course, tuples would still be a special case because they may contain mutable objects. You need to check they're immutable all the way down. Nothing to do with threading, but it's also the cause of this weirdness: http://bytes.com/topic/python/answers/752154-list-tuple >>a = ([1], 2) >>a[0] += [3] succeeds, but raises an error. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Sep 7, 6:47 pm, ganesh wrote: > On Sep 7, 3:41 pm, Graham Dumpleton > wrote: > > > On Sep 7, 3:42 pm, sturlamolden wrote: > > interpreters. The simplified GIL state API you mentioned only works > > for threads operating in the main (first) interpreter created within > > the process. > > I modified my program to have Py_Initialize and compilation of one > Python function done in main() thread. Then I am calling only that > function in callPyFunction() thread. But, this thread does not come > out of PyGILState_Ensure() function. > > > The OP can do what they want, but they need to user lower level > > routines for creating their own thread state objects and acquiring the > > GIL against them. > > > Graham > > What are the "lower level routines" for creating own thread state > objects & acquiring GILs. > Also, where can I find more information about those routines? Documentation is at: http://docs.python.org/c-api/init.html Are you really using sub interpreters though? There is no evidence of that in the code you posted earlier. Sure you just don't understand enough about it and so are using the wrong terminology and all you really want to do is run externally created threads through the one interpreter. Using sub interpreters is not for the feint of heart and not something you want to do unless you want to understand Python C API internals very well. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
ganesh wrote: >> Did you remeber to acquire the GIL? The GIL is global to the process > > No, I did not use GIL. > > -- Why do we need to use GIL even though python is private to each > thread? Quoting from above: "The GIL is global to the process". So no, it is NOT private to each thread which means "python" isn't either. At least that is my understanding of the issue. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Something confusing about non-greedy reg exp match
George Burdell wrote: On Sep 6, 10:06 pm, "Mark Tolonen" wrote: wrote in message news:f98a6057-c35f-4843-9efb-7f36b05b6...@g19g2000yqo.googlegroups.com... If I do this: import re a=re.search(r'hello.*?money', 'hello how are you hello funny money') I would expect a.group(0) to be "hello funny money", since .*? is a non-greedy match. But instead, I get the whole sentence, "hello how are you hello funny money". Is this expected behavior? How can I specify the correct regexp so that I get "hello funny money" ? A non-greedy match matches the fewest characters before matching the text *after* the non-greedy match. For example: import re a=re.search(r'hello.*?money','hello how are you hello funny money and more money') a.group(0) # non-greedy stops at the first money 'hello how are you hello funny money'>>> a=re.search(r'hello.*money','hello how are you hello funny money and more money') a.group(0) # greedy keeps going to the last money 'hello how are you hello funny money and more money' This is why it is difficult to use regular expressions to match nested objects like parentheses or XML tags. In your case you'll need something extra to not match the first hello. a=re.search(r'(? 'hello funny money' -Mark I see now. I also understand r's response. But what if there are many "hello"'s before "money," and I don't know how many there are? In other words, I want to find every occurrence of "money," and for each occurrence, I want to scan in the reverse (left) direction to the closest occurrence of "hello." How can this be done? >>> a = re.search(r'hello(?!.*?hello).*?money', 'hello how are you hello funny money') >>> a.group(0) 'hello funny money' -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
Actually, I modified my program to have a single shared Py-interpreter across all threads to test the usage of GIL. So, I did Py_Initialize in main() function and only called that python function in different threads. But this is not the way I want to use interpreters in my code. I am looking for using sub-interpreters, only that I did not know this this term, till you mentioned it here. So bvefore this, I was calling py_Initialize in each of the C++ level threads, which was wrong. I should be using Py_NewInterpreter() in my threads and Py_Initialize () in main() thread. Please correct me if I am wrong. not something you want to do unless you want to understand Python C API internals very well. Are these APIs really tricky to use with C++ embedding? Can't they be implemented thru C APIs? I need to use these to get the proper concurrency in my multi-threaded application without any synchronization mechanisms. -- http://mail.python.org/mailman/listinfo/python-list
Re: zip a huge file into multiple small ones
krishna chaitanya wrote: I am new to dealing with zip files in python. I have a huge file which i need to zip and send as an attachment through email. My email restrictions are not allowing me to send it in one go. Is there a way to split this file into multiple zip files, so that i can mail them separately. All the individual zip files should be linked. I should be able to extract the original file by extracting the first of the small zip files. You're using the wrong medium. Upload the file to an http server somewhere and just include a link in the email... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: httplib incredibly slow :-(
Dieter Maurer wrote:
Chris Withers writes on Thu, 13 Aug 2009 08:20:37
+0100:
...
I've already established that the file downloads in seconds with
[something else], so I'd like to understand why python isn't doing the
same and fix the problem...
A profile might help to understand what the time is used for.
As almost all operations are not done in Python itself ("httplib" is really
a very tiny wrapper above a socket), a C level profile may be necessary
to understand the behaviour.
Actually, the problem *was* in Python:
http://bugs.python.org/issue2576
Found and fixed :-)
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list
Re: zip a huge file into multiple small ones
On Mon, Sep 7, 2009 at 4:57 AM, Chris Withers wrote: > krishna chaitanya wrote: >> >> I am new to dealing with zip files in python. >> I have a huge file which i need to zip and send as an attachment through >> email. >> My email restrictions are not allowing me to send it in one go. >> Is there a way to split this file into multiple zip files, so that i can >> mail them separately. >> All the individual zip files should be linked. >> I should be able to extract the original file by extracting the first of >> the small zip files. > > You're using the wrong medium. Upload the file to an http server somewhere > and just include a link in the email... One such free service, among many others: http://drop.io/ Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 7 Sep, 13:53, ganesh wrote: > I need to use these to get the proper concurrency in my multi-threaded > application without any synchronization mechanisms. Why will multiple interpreters give you better concurrency? You can have more than one thread in the same interpreter. Here is the API explained: http://docs.python.org/c-api/init.html http://www.linuxjournal.com/article/3641 -- http://mail.python.org/mailman/listinfo/python-list
Re: beginner's python help
Maggie wrote:
code practice:
test = open ("test.txt", "r")
readData = test.readlines()
#set up a sum
sum = 0;
Hi Maggie,
I see you have already gotten a lot of useful help.
One additional suggestion would be to use a different
variable name other than 'sum' as sum is a Python
built-in function.
Cheers,
Esmail
--
http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 7 Sep, 13:17, Ulrich Eckhardt wrote: > Quoting from above: "The GIL is global to the process". So no, it is NOT > private to each thread which means "python" isn't either. > > At least that is my understanding of the issue. Strictly speaking, the GIL is global to the Python DLL, not the process. You can load it multiple times from different paths, and if you do GIL with not be shared. If you make several clean installs of Python on Windows (say c: \Python26-0 ... c:\Python26-3), you can embed multiple interpreters in a process, and they will not share GIL or anything else. But be careful: all *.pyd files must reside in these directories, or they will be loaded once and refcounts screw up. The Python DLL must also be in these directories, not in c:\windows\system32. It is in fact possible to make Python utilize dual- and quad-core processors on Windows this way. You can even use ctypes for embedding Python into Python, so no C is required. See: http://groups.google.no/group/comp.lang.python/browse_thread/thread/2d537ad8df9dab67/812013f9ef3a766d To make this hack really work one need multiple complete installs, not just copies of one DLL as I assumed in the thread. But the general method is the same. You can see this as a form of primitive object orientation :P Sturla Molden -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
sturlamolden wrote: On 7 Sep, 13:53, ganesh wrote: I need to use these to get the proper concurrency in my multi-threaded application without any synchronization mechanisms. Why will multiple interpreters give you better concurrency? You can have more than one thread in the same interpreter. Here is the API explained: http://docs.python.org/c-api/init.html http://www.linuxjournal.com/article/3641 CPython's GIL means that multithreading on multiple processors/cores has limitations. Each interpreter has its own GIL, so processor-intensive applications work better using the multiprocessing module than with the threading module. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 7 Sep, 14:50, MRAB wrote: > CPython's GIL means that multithreading on multiple processors/cores has > limitations. Each interpreter has its own GIL, so processor-intensive > applications work better using the multiprocessing module than with the > threading module. We incur a 200x speed-penalty from Python if the code is CPU-bound. How much do you gain from one extra processor? Start by adding in some C, and you will gain much more performance, even without parallel processing. Processor-intensive code should therefore use extension libraries that release the GIL. Then you have option of getting parallel concurrency by Python threads or OpenMP in C/Fortran. Most processor-intensive code depend on numerical libraries written in C or Fortran anyway (NumPy, ATLAS, LAPACK, FFTW, GSL, MKL, etc.) When you do this, the GIL does not get in your way. The GIL is infact an advantage if one library happen not to be thread safe. Many old Fortran 77 libraries have functions with re-entrancy issues, due to SAVE attribute on variables. Thus, the GIL is often an advantage for processor-intensive code. multiprocessing is fragile and unreliable, btw. -- http://mail.python.org/mailman/listinfo/python-list
Re: Something confusing about non-greedy reg exp match
On Sep 6, 11:23 pm, Ben Finney wrote:
> George Burdell writes:
> > I want to find every occurrence of "money," and for each
> > occurrence, I want to scan back to the first occurrence
> > of "hello." How can this be done?
>
> By recognising the task: not expression matching, but lexing and
> parsing. For which you might find the ‘pyparsing’ library of use
> http://pyparsing.wikispaces.com/>.
>
Even pyparsing has to go through some gyrations to do this sort of
"match, then backup" parsing. Here is my solution:
>>> from pyparsing import SkipTo, originalTextFor
>>> expr = originalTextFor("hello" + SkipTo("money", failOn="hello",
>>> include=True))
>>> print expr.searchString('hello how are you hello funny money')
[['hello funny money']]
SkipTo is analogous to the OP's .*?, but the failOn attribute adds the
logic "if this string is found before matching the target string, then
fail". So pyparsing scans through the string, matches the first
"hello", attempts to skip to the next occurrence of "money", but finds
another "hello" first, so this parse fails. Then the scan continues
until the next "hello" is found, and this time, SkipTo successfully
finds "money" without first hitting a "hello". I then had to wrap the
whole thing in a helper method originalTextFor, otherwise I get an
ugly grouping of separate strings.
So I still don't really have any kind of "backup after matching"
parsing, I just turned this into a qualified forward match. One could
do a similar thing with a parse action. If you could attach some kind
of validating function to a field within a regex, you could have done
the same thing there.
-- Paul
--
http://mail.python.org/mailman/listinfo/python-list
Re: simple string question
On Mon, 7 Sep 2009 15:29:23 +1000
"jwither" wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
I don't know what your actual requirement is but maybe this fits:
exec("print '%s'" % x)
--
D'Arcy J.M. Cain | Democracy is three wolves
http://www.druid.net/darcy/| and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list
Smallest float different from 0.0?
Is there some standardized way (e.g. some "official" module of such limit constants) to get the smallest positive float that Python will regard as distinct from 0.0? TIA! kj -- http://mail.python.org/mailman/listinfo/python-list
Validation in RPC call?
I'm building an RPC service, and I need to validate the input and provide informative error messages to users. What would be the best way to do this? Simple `if` statements each raising a custom exception? `assert` statements inside a try/except block to "translate" the assertion errors into something more meaningful? -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest float different from 0.0?
On Sep 7, 9:47 am, kj wrote: > Is there some standardized way (e.g. some "official" module of such > limit constants) to get the smallest positive float that Python > will regard as distinct from 0.0? > > TIA! > > kj You could find it for yourself: >>> for i in range(400): ...if 10**-i == 0: ... print i ... break ... 324 -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest float different from 0.0?
Paul McGuire wrote: > On Sep 7, 9:47 am, kj wrote: >> Is there some standardized way (e.g. some "official" module of such >> limit constants) to get the smallest positive float that Python >> will regard as distinct from 0.0? >> >> TIA! >> >> kj > > You could find it for yourself: > for i in range(400): > ...if 10**-i == 0: > ... print i > ... break > ... > 324 I think this is even a bit closer: for i in xrange(1): try: v = 1 / (2**-i) except ZeroDivisionError: print i, v break -> 1075 If you test the inverse (10 ** 324 and 2 ** 1075) you see that the binary variant is 4.something * 10 ** 323. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest float different from 0.0?
On Sep 7, 3:47 pm, kj wrote: > Is there some standardized way (e.g. some "official" module of such > limit constants) to get the smallest positive float that Python > will regard as distinct from 0.0? > > TIA! > > kj There's sys.float_info.min: >>> import sys >>> sys.float_info sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.2204460492503131e-16, radix=2, rounds=1) >>> sys.float_info.min 2.2250738585072014e-308 But that only gives you the smallest *normal* positive float, which is 2**-1022 on most systems. The smallest positive subnormal value is usually 2**-1074. If you want something that would still work if Python ever switched to using IEEE 754 binary128 format (or some other IEEE 754 format), then sys.float_info.min * 2**(1-sys.float_info.mant_dig) will work. But on 99.99%+ of systems you'll find Python running on, it's going to be 2**-1074. Mark -- http://mail.python.org/mailman/listinfo/python-list
Smallest float different from 0.0?
This topic came up before. =] See below. Not sure how 'standardised' this
is, though.
Double precision:
>>> import struct
>>> struct.unpack('d', struct.pack('Q', 1))[0]
4.9406564584124654e-324
Float precision:
>>> struct.unpack('f', struct.pack('L', 1))[0]
1.4012984643248171e-45
Cheers,
Xavier
--
http://mail.python.org/mailman/listinfo/python-list
Re: Smallest float different from 0.0?
In Mark Dickinson writes: >On Sep 7, 3:47=A0pm, kj wrote: >> Is there some standardized way (e.g. some "official" module of such >> limit constants) to get the smallest positive float that Python >> will regard as distinct from 0.0? >> >> TIA! >> >> kj >There's sys.float_info.min: import sys sys.float_info Ah! I'd seen sys.float_info when searched for this online, but incorrectly inferred that it was the name of a module. This is what I was looking for. Thanks! kynn -- http://mail.python.org/mailman/listinfo/python-list
Re: [Guppy-pe-list] An iteration idiom (Was: Re: loading files containing multiple dumps)
Sverker Nilsson wrote: I hope the new loadall method as I wrote about before will resolve this. def loadall(self,f): ''' Generates all objects from an open file f or a file named f''' if isinstance(f,basestring): f=open(f) while True: yield self.load(f) It would be great if load either returned just one result ever, or properly implemented the iterator protocol, rather than half implementing it... Should we call it loadall? It is a generator so it doesn't really load all immedietally, just lazily. Maybe call it iload? Or redefine load, but that might break existing code so would not be good. loadall works for me, iload doesn't. Minor rant, why do I have to instantiate a to do anything with heapy? Why doesn't heapy just expose load, dump, etc? Basically, the need for the h=hpy() idiom is to avoid any global variables. Eh? What's h then? (And h will reference whatever globals you were worried about, surely?) Heapy uses some rather big internal data structures, to cache such things as dict ownership. I didn't want to have all those things in global variables. What about attributes of a class instance of some sort then? the other objects you created. Also, it allows for several parallel invocations of Heapy. When is that helpful? However, I am aware of the extra initial overhead to do h=hpy(). I discussed this in my thesis. "Section 4.7.8 Why not importing Use directly?" page 36, http://guppy-pe.sourceforge.net/heapy-thesis.pdf I'm afraid, while I'd love to, I don't have the time to read a thesis... Try sunglasses:) (Well, I am aware of this, it was a research/experimental system and could have some refactoring :-) I would suggest creating a minimal system that allows you to do heap() and then let other people build what they need from there. Simple is *always* better... Less minor rant: this applies to most things to do with heapy... Having __repr__ return the same as __str__ and having that be a long lump of text is rather annoying. If you really must, make __str__ return the big lump of text but have __repr__ return a simple, short, item containing the class, the id, and maybe the number of contained objects... I thought it was cool to not have to use print but get the result directly at the prompt. That's fine, that's what __str__ is for. __repr__ should be short. Hmmm, I'm sure there's a good reason why an item in a set has the exact same class and iterface as a whole set? Um, perhaps no very good reason but... a subset of a set is still a set, isn't it? Yeah, but an item in a set is not a set. __getitem__ should return an item, not a subset... I really think that, by the sounds of it, what is currently implemented as __getitem__ should be a `filter` or `subset` method on IdentitySets instead... objects. Each row is still an IdentitySet, and has the same attributes. Why? It's semantically different. .load() returns a set of measurements, each measurement contains a set of something else, but I don't know what... This is also like Python strings work, there is no special character type, a character is just a string of length 1. Strings are *way* more simple in terms of what they are though... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest float different from 0.0?
In Mark Dickinson writes: >The smallest positive subnormal value >is usually 2**-1074. If you want something that would still work >if Python ever switched to using IEEE 754 binary128 format (or some >other IEEE 754 format), then >sys.float_info.min * 2**(1-sys.float_info.mant_dig) Hmmm. This close-to-the-metal IEEE stuff make a "HERE BE DRAGONS!" alarms go off in my head... (What's up with that correction by 1 to sys.float_info.mant_dig? Or, probably equivalently, why would sys.float_info.min_exp (-1021) be off by 1 relative to log2 of sys.float_info.min (-1022)?) I suppose that 2**(sys.float_info.min_exp - sys.float_info.mant_dig) would also work? I must confess, this stuff is way beyond me... I'm glad that sys.float_info is available... kynn -- http://mail.python.org/mailman/listinfo/python-list
Flowcharting in Python?
Hi guys, Does anyone know of any code or projects around that are written in Python or can be used by Python to write a flowcharting application? I haven't been able to find any, but the closest thing I have come across is FlowchartPython which allows you to code in Python from flowcharts, which isn't what I want; something more like Microsoft Visio. I'm beginning to think I'll have to create something from scratch. Thanks. :) -- http://mail.python.org/mailman/listinfo/python-list
How do I post to the wxPython mailing list?
Hi Since I have been told in this group to post wxPython related topics in the wxPython-users mailing list instead of here, I just tried doing that. However, I always get an error message back when using gmane. Mailing directly, there is no error message but the message does not appear in the list anyway. Looking at google groups, they want me to open an account just for posting. I do not intend to open a Google account. Is there a workarounf to post in the mailing list? Is there non-Google access? Should I keep posting wxPython related topics here? Best Regards Martin -- http://mail.python.org/mailman/listinfo/python-list
How do I post to the wxPython mailing list?
Hi Since I have been told in this group to post wxPython related topics in the wxPython-users mailing list instead of here, I just tried doing that. However, I always get an error message back when using gmane. Mailing directly, there is no error message but the message does not appear in the list anyway. Looking at Google groups, they want me to open an account just for posting. I do not intend to open a Google account. Is there a workaround to post in the mailing list? Is there non-Google access? Should I keep posting wxPython related topics here? Best Regards Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On Sep 7, 2009, at 12:52 PM, [email protected] wrote: Hi Since I have been told in this group to post wxPython related topics in the wxPython-users mailing list instead of here, I just tried doing that. However, I always get an error message back when using gmane. Mailing directly, there is no error message but the message does not appear in the list anyway. Did you subscribe to the mailing list before sending a message to it? -- http://mail.python.org/mailman/listinfo/python-list
Re: beginner's python help
On 6 Sep, 09:00, Maggie wrote:
> code practice:
>
> test = open ("test.txt", "r")
> readData = test.readlines()
> #set up a sum
> sum = 0;
> for item in readData:
> sum += int(item)
> print sum
>
> test file looks something like this:
>
> 34
> 23
> 124
> 432
> 12
>
>>> sum(map(int, open('test.txt', 'r')))
Assuming the test file looks like above, and isn't stored in rtf
format or something like that. (Open the test file in the python
editor to check its contents).
/Niklas
--
http://mail.python.org/mailman/listinfo/python-list
Re: Something confusing about non-greedy reg exp match
"[email protected]" wrote: > If I do this: > > import re > a=re.search(r'hello.*?money', 'hello how are you hello funny money') > > I would expect a.group(0) to be "hello funny money", since .*? is a > non-greedy match. But instead, I get the whole sentence, "hello how > are you hello funny money". > > Is this expected behavior? How can I specify the correct regexp so > that I get "hello funny money" ? > > Another option nobody has yet suggested: >>> re.match(r'.*(hello.*?money)', 'hello how are you hello funny >>> money').group(1) 'hello funny money' The initial .* will effectively make the search start at the end and work backwards so it finds the last 'hello' that is followed by 'money' instead of the first. -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest float different from 0.0?
On Sep 7, 5:08 pm, kj wrote: > Hmmm. This close-to-the-metal IEEE stuff make a "HERE BE DRAGONS!" > alarms go off in my head... (What's up with that correction by 1 > to sys.float_info.mant_dig? Or, probably equivalently, why would > sys.float_info.min_exp (-1021) be off by 1 relative to log2 of > sys.float_info.min (-1022)?) The sys.float_info constants come straight from the standard C limits defined in float.h. The C standards choose to describe floats in the form sign * 2**exponent * significand with 0.5 <= significand < 1.0. (Well, assuming base 2; the actual standard is a bit more general than this; see e.g. section 5.2.4.2.2 of C99.) So from C's point of view, the smallest normal value comes from the minimum exponent (-1021) together with the minimum significand (0.5), so it's 2**-1021 * 0.5, or 2**-1022. Similarly, the max value is (1-2**-53)*2**1024. It's a bit unfortunate that the IEEE 754 standard prefers a different normalization, with the exponent chosen so that the significand is in [1.0, 2.0). So where IEEE 754-2008 gives emax as 1023, C gives DBL_MAX_EXP as 1024; both describing exactly the same format. > I suppose that > > 2**(sys.float_info.min_exp - sys.float_info.mant_dig) > > would also work? Yes. This all only works for IEEE 754 binary formats, though. Most other floating-point formats you're likely to meet (IBM hex floats, VAX D and G, Cray floats, etc.) don't have gradual underflow and subnormals. -- Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Validation in RPC call?
Phillip B Oldham wrote: I'm building an RPC service, and I need to validate the input and provide informative error messages to users. What would be the best way to do this? Simple `if` statements each raising a custom exception? `assert` statements inside a try/except block to "translate" the assertion errors into something more meaningful? Use 'if'. Asserts are for debugging program logic (and hence can be optimized away), not for user input. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On Sep 7, 12:50 pm, [email protected] wrote: > Hi > > Since I have been told in this group to post wxPython related topics in > the wxPython-users mailing list instead of here, I just tried doing > that. > > However, I always get an error message back when using gmane. > Mailing directly, there is no error message but the message does not > appear in the list anyway. > > Looking at google groups, they want me to open an account just for > posting. I do not intend to open a Google account. > > Is there a workarounf to post in the mailing list? > Is there non-Google access? > Should I keep posting wxPython related topics here? > > Best Regards > > Martin http://lmgtfy.com/?q=wxpython+mailing+list -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
Graham Breed wrote: John Nagle wrote: In the beginning, strings, tuples, and numbers were immutable, and everything else was mutable. That was simple enough. But over time, Python has acquired more immutable types - immutable sets and immutable byte arrays. Each of these is a special case. Immutability is interesting for threaded programs, because immutable objects can be shared without risk. Consider a programming model where objects shared between threads must be either immutable or "synchronized" in the sense that Java uses the term. Such programs are free of most race conditions, without much programmer effort to make them so. Of course, tuples would still be a special case because they may contain mutable objects. You need to check they're immutable all the way down. Right. Tracking mutablity and ownership all the way down without making the language either restrictive or slow is tough. In multi-thread programs, though, somebody has to be clear on who owns what. I'm trying to figure out a way for the language, rather than the programmer, to do that job. It's a major source of trouble in threaded programs. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Math Notations, Computer Languages, and the “F orm” in Formalism
2009-09-07 On Sep 5, 7:41 am, slawekk wrote: > > Theorem provers > > such as OCaml (HOL, Coq), Mizar does math formalism as a foundation, > > also function as a generic computer language, but lacks abilities as a > > computer algebra system or math notation representation. > > Isabelle's presentation layer is well integrated with LaTeX and you > can use math notation in (presentation of) proofs. in my previous post http://xahlee.org/cmaci/notation/index.html it was quickly written and didn't clearly bring about my point. The point is, that formalism in mathematics, consistency of math notation issues (for human), math notation language systems (TeX, Mathematica, MathML), and calculational proof movement (a la Edsger Dijkstra), and computer algebra systems, and theorem proving systems, and computer language syntax, all of the above, should be unified into one single entity, and is today very much doable, in fact much of it is happening in disparate communities, but as far as i know i do not think there's any literature that expresses the idea that they should all be rolled into one. Let me address this a bit quickly without trying to write some coherent essay. few things to note: -- • theorem proving systems and computer algebra systems as unified tool is very much a need and is already happening. (e.g. there's a project i forgot the name now that tries to make Mathematica into a theorem proving system a la ocaml) -- • theorem proving systems (isabell, hol, coq etc, “proof assistants” or “automated proof systems”) and mathematics foundation by formalism should be unified. This active research the past 30 or more years, and is the explicit goal of the various theorem proving systems. -- • math notation consistency issues for human communication, as the calculational proof movement by Dijkstra, and also Stephen Wolfram criticism of traditional notation and Mathematica's StandardForm, is actually one single issue. They should be know as one single issue, instead of Calculational Proof movement happening only in math pedagogy community and Mathematica in its own community. -- • math notation issues and computer language syntax and logic notation syntax is also largely the same issue. Computer languages, or all computer languages, should move towards a formalized syntax system. I don't think there's much literature on this aspect (in comparison to other issues i mentioned in this essay). Most of today's computer languages's syntax are ad hoc, with no foundation, no consistency, no formal approach. e.g. especially bad ones are Ocaml, and all C-like langs such as C, C++, Java. Shell langs are also good examples of extremely ad hoc: e.g. bash, perl, PowerShell. There are langs that are more based on a consistent syntax system that are more or less can be reduced to a formal approach. Of those i know includes Mathematica, XML (and lots derivatives e.g. MathML) and lisps also. Other langs i don't know much but whose syntax i think are also close to a formal system are: APL, tcl. My use of the phrase “syntax with formal foundation” or “syntax system” is a bit fuzzy and needs more thinking and explanation... but basically, the idea is that computer language's syntax can be formalize in the same way we trying to formalize mathematics (albeit the problem is much simpler), so that the syntax and grammar can be reduced to few very simple formal rules in parsing it, is consistent, easy to understand. Mathematica and XML are excellent examples. (note here that such syntax system does not imply they look simple. Mathematica is a example.) the following 2 articles helps in explaining this: • The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations http://xahlee.org/UnixResource_dir/writ/notations.html • Fundamental Problems of Lisp http://xahlee.org/UnixResource_dir/writ/lisp_problems.html -- • systems for displaying math, such as TeX, Mathematica, MathML, should be unified as part of the computer language's syntax. The point is that we should not have a lang just to generate the display of math notations such as done by TeX or MathML or Microsoft equation editor or other tools. Rather, it should be part of the general language for doing math. (e.g. any computer algebra system or theorem proving system) A good example that already have done this since ~1997 is Mathematica. practically speaking, this means, when you code in a language (say, Ocaml), you don't just write code, but you can dynamically, interactively, have your code display math 2D notations, and the info about formating the notation is part of the computer language, it's just that your IDE or specialized editor understand your language and can format it to render 2D notations on the fly (e.g. HTML is such a lang). If you know Mathematica, then you understand this. Otherwise, think of HTML/XML, which is a lang for formatting purposes without computational ability, yet today ther
Re: HTTPS on Twisted
On Sep 6, 7:53 pm, koranthala wrote: > Hi, > For a financial application, I am creating a python tool which > uses HTTPS to transfer the data from client to server. Now, everything > works perfectly, since the SSL support comes free with Twisted. > I have one problem though. As an upgrade, now, I have to send many > requests as the same client to the server. Many in the range of >10 > msgs every second. Now, I am creating a separate TCP connection for > each and am sending the data. Is it possible to create just one SSL > and TCP connection and send each message over that using Twisted? > I read through Twisted, but was unable to come up with the answer > though. Even if I have to use multiple TCP connections, is it possible > to have just one SSL connection? > > I think persistent connections should be possible for TCP, but is > it possible is Twisted? Any comments on the same? -- http://mail.python.org/mailman/listinfo/python-list
Re: Flowcharting in Python?
Justin wrote: Hi guys, Does anyone know of any code or projects around that are written in Python or can be used by Python to write a flowcharting application? I haven't been able to find any, but the closest thing I have come across is FlowchartPython which allows you to code in Python from flowcharts, which isn't what I want; something more like Microsoft Visio. I'm beginning to think I'll have to create something from scratch. Thanks. :) have you looked at the OGL module or FloatCanvas in wxPython ? I also have a simplified version (10% of the code) but more powerful OGL-like, see here some examples what you can do with OGL-like http://mientki.ruhosting.nl/data_www/pylab_works/pw_circuit_editor.html http://mientki.ruhosting.nl/data_www/pylab_works/pw_bricks_2d_scene.html cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTPS on Twisted
On 07:20 pm, [email protected] wrote: On Sep 6, 7:53�pm, koranthala wrote: Hi, � �For a financial application, �I am creating a python tool which uses HTTPS to transfer the data from client to server. Now, everything works perfectly, since the SSL support comes free with Twisted. � �I have one problem though. As an upgrade, now, I have to send many requests as the same client to the server. Many in the range of >10 msgs every second. Now, I am creating a separate TCP connection for each and am sending the data. Is it possible to create just one SSL and TCP connection and send each message over that using Twisted? � �I read through Twisted, but was unable to come up with the answer though. Even if I have to use multiple TCP connections, is it possible to have just one SSL connection? � �I think persistent connections should be possible for TCP, but is it possible is Twisted? You can probably get persistent http connections working with twisted.web.client (not with getPage or the other "convenience" functions though). The new http client which is being developed will support this in a much simpler way. With a bit of luck (or maybe some additional help from people interested in a really high-quality http client), this should be included in Twisted 9.0 which I hope will be out very soon. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Module for Fisher's exact test?
On Sep 7, 3:50 am, gb345 wrote: > Before I roll my own, is there a good Python module for computing > the Fisher's exact test stastics on 2 x 2 contingency tables? Not in the standard library, certainly. Have you tried SciPy and RPy? -- Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
John Nagle writes: > Right. Tracking mutablity and ownership all the way down without > making the language either restrictive or slow is tough. > > In multi-thread programs, though, somebody has to be clear on who owns > what. I'm trying to figure out a way for the language, rather than the > programmer, to do that job. It's a major source of trouble in threaded > programs. Python's threading system is modelled after Java's, which basically uses explicit locks under programmer control. That has its hazards but does manage to multiprocess effectively. CPython's multiprocessing is limited by the notorious GIL, but that's an implementation artifact. Having the language automatically manage ownership of mutable objects without a fancy type system sounds self-contradictory. Erlang (which is typeless like Python) does it by not allowing mutation at all. Haskell uses a type-based scheme around software transactional memory (STM) primitives: http://book.realworldhaskell.org/read/software-transactional-memory.html The Microsoft Research "Singularity" OS may also be of interest. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
[email protected] wrote: Hi Since I have been told in this group to post wxPython related topics in the wxPython-users mailing list instead of here, I just tried doing that. However, I always get an error message back when using gmane. Which is ??? -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
On Sep 6, 10:48 pm, The Music Guy wrote:
> Sorry, that last code had a typo in it:
>
> #!/usr/bin/python
>
> def main():
> foox = FooX()
> fooy = FooY()
> fooz = FooZ()
>
> foox.method_x("I", "AM", "X")
> print
> fooy.method_x("ESTOY", "Y", "!")
> print
> fooz.method_x(100, 200, 300)
>
> class MyMixin(object):
>
> def method_x(self, a, b, c):
> super(MyMixin, self).method_x(a, b, c)
> print "MyMixin.method_x(%s, %s, %s, %s)" % (repr(self),
> repr(a), repr(b), repr(c))
>
> class BaseA(object):
>
> def method_x(self, a, b, c):
> super(BaseA, self).method_x(a, b, c)
> print "BaseA.method_x(%s, %s, %s, %s)" % (repr(self), repr(a),
> repr(b), repr(c))
>
> class BaseB(object):
>
> pass
>
> class BaseC(object):
>
> def method_x(self, a, b, c):
> super(BaseC, self).method_x(a, b, c)
> print "BaseC.method_x(%s, %s, %s, %s)" % (repr(self), repr(a),
> repr(b), repr(c))
>
> class FooX(BaseA, MyMixin):
>
> def method_x(self, a, b, c):
> super(FooX, self).method_x(a, b, c)
> print "FooX.method_x(%s, %s, %s, %s)" % (repr(self), repr(a),
> repr(b), repr(c))
>
> class FooY(BaseB, MyMixin):
>
> pass
>
> class FooZ(BaseC, MyMixin):
>
> def method_x(self, a, b, c):
> super(FooZ, self).method_x(a, b, c)
> print "FooZ.method_x(%s, %s, %s, %s)" % (repr(self), repr(a),
> repr(b), repr(c))
>
> if __name__ == '__main__':
> main()
>
> Traceback (most recent call last):
> File "foo.py", line 54, in
> main()
> File "foo.py", line 8, in main
> foox.method_x("I", "AM", "X")
> File "foo.py", line 40, in method_x
> super(FooX, self).method_x(a, b, c)
> File "foo.py", line 24, in method_x
> super(BaseA, self).method_x(a, b, c)
> File "foo.py", line 18, in method_x
> super(MyMixin, self).method_x(a, b, c)
> AttributeError: 'super' object has no attribute 'method_x'
That's not what you did in your original post, though.
Mixins should be listed first among bases, which is how you did it in
your original post, and how it had to be in order for it to "just
work" as I claimed.
class FooX(MyMixin, BaseA)
class FooY(MyMixin, BaseB)
class FooZ(MyMixin, BaseC)
If you are concerned that a base class might not define method_x (and
therefore that the super call from MyMixin would fail), then there are
a couple things you can do. First thing is to consider whether you
ought to be using two method instead of one.
Otherwise the easiest thing is to catch and ignore AttributeError from
MyMixin's method_x:
class MyMixin(object):
def method_x(self, a, b, c):
try:
f = super(MyMixin, self).method_x
except AttributeError:
pass
else:
f(a,b,c)
Note that you don't want to call the super inside the try block
otherwise you risk catching spurrious AttributeErrors.
This strategy might hide some typo-style errors with the base class,
so if you're worried about that, another strategy would be to define
another mixin which provides an empty method_x:
class ProvideMethodX(self):
def method_x(self, a, b, c):
pass
Then if BaseB does not define method_x, derive FooY from it like this:
class FooY(MyMixin,ProvideMethodX,BaseB)
Finally (and probably least confusingly) you could use separate mixins
for bases that define method_x and those that don't.
Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On Mon, 07 Sep 2009 16:06:11 -0400 Terry Reedy wrote: > [email protected] wrote: > > Hi > > > > Since I have been told in this group to post wxPython related > > topics in the wxPython-users mailing list instead of here, I just > > tried doing that. > > > > However, I always get an error message back when using gmane. > > Which is ??? I pasted the e-mail that I received upon posting via the gmane interface below. I am not sure how to subscribe the gmane account. > From: [email protected] > To: [email protected] > Subject: Posting error: wxPython-users > Date: Mon, 07 Sep 2009 16:36:58 + > > Hello [email protected], > > We're writing to let you know that the group that you tried to contact > (wxpython-users) either doesn't exist, or you don't have permission > to post to it. There are a few possible reasons why this happened: > > * You might have spelled or formatted the group name incorrectly. > * The owner of the group removed this group, so there's nobody there > to contact. > * You may need to join the group before being allowed to post. > * This group may not be open to posting. > > If you have questions about this or any other group, please visit > the Google Groups Help Center at http://groups.google.com/support. > > Thanks, and we hope you'll continue to enjoy Google Groups. > > The Google Groups Team -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On Mon, 7 Sep 2009 13:04:39 -0400 Philip Semanchuk wrote: > Did you subscribe to the mailing list before sending a message to it? I did not subscribe the gmane account when I tried out posting via gmane. I am pretty sure that I already subscribed to the group in the past. Nevertheless, I subscribed again (via e-mail). I got a validation e-mail that I confirmed but posting to the list still does result in no message appearing in the list. No error mail came back either. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On Mon, 7 Sep 2009 22:51:47 +0200 [email protected] wrote: > On Mon, 7 Sep 2009 13:04:39 -0400 > Philip Semanchuk wrote: > > > Did you subscribe to the mailing list before sending a message to > > it? > > I did not subscribe the gmane account when I tried out posting via > gmane. > > I am pretty sure that I already subscribed to the group in the past. > Nevertheless, I subscribed again (via e-mail). I got a validation > e-mail that I confirmed but posting to the list still does result in > no message appearing in the list. No error mail came back either. I just see that it worked now. Processing took a while, I guess. Sorry for the noise. Martin -- http://mail.python.org/mailman/listinfo/python-list
Noddy with submodules?
Hi, i want to write a Python module that interfaces a DLL that we use in the office to do some measurement. So i'd like to write a python module in C (which i did before some times). But i'm not sure how i can create a module in a way that i can later do: import measurement import measurement.adc import measurement.adc.channels import measurement.pwm What do i need to do to create submodules within the initialisation code of a python module written in C? Maybe there is an example based on "noddy"? Thanks for any hints, Torsten. -- http://mail.python.org/mailman/listinfo/python-list
Re: Flowcharting in Python?
On 2009-09-07, Justin wrote: > Does anyone know of any code or projects around that are > written in Python or can be used by Python to write a > flowcharting application? Have you looked at Skencil (nee Sketch)? It's a vector/object-oriented drawing program written in Python: http://www.skencil.org/ It's not really optimized for flowcharts or block diagrams (IIRC, it doens't have any concept of connecting arcs between polygrams), but you might be able to extend it. > I'm beginning to think I'll have to create something from scratch. I wouldn't think you'd have to start from scratch. You should at least use one of the GUI frameworks that has some sort of canvas widget. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Scheduling algorithm: Suggestions?
Hello, I have a batch of "rpc style" calls that I must make to an external server via HTTP in a multi threaded fashion. (Return vales must be saved.) Problem is, I need to throttle the rate at which I do this. Each HTTP call takes between 0.2 and several seconds to complete. I need to control two different aspects: 1) Number of new connections per second. 2) Total number of parallel connections allowed. Additionally, it is possible that an HTTP call could result in an error at the remote server. If so, it must be retried couple of times before an error is logged. Does anybody have a suggestions as to the correct way to implement such a system in Python? Thank you, :) -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On 2009-09-07, wrote: >> > However, I always get an error message back when using gmane. >> >> Which is ??? > > I pasted the e-mail that I received upon posting via the gmane > interface below. >> * You may need to join the group before being allowed to post. That probably means you need to join the mailing list before being allowed to post. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On 7 sep 2009, at 22:51, [email protected] wrote: On Mon, 7 Sep 2009 13:04:39 -0400 Philip Semanchuk wrote: Did you subscribe to the mailing list before sending a message to it? I did not subscribe the gmane account when I tried out posting via gmane. I am pretty sure that I already subscribed to the group in the past. Nevertheless, I subscribed again (via e-mail). I got a validation e- mail that I confirmed but posting to the list still does result in no message appearing in the list. No error mail came back either. pfff You just woke me up too...! The list apperently changed to a google group list. Did i miss a warning or did they just change it without notice? I dont want to register with a google account, is there any way to use a non-gmail account? gr Arno -- http://mail.python.org/mailman/listinfo/python-list
Windows, CreateThread
Hi, in a python C module i may need to create a Thread to do some background observations / calculations. Are there any problems with Python doing something like this? Is there some special support on sharing data? I guess i can't call any Python functions from the thread, correct? Thanks for any hints, Torsten. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Mon, Sep 7, 2009 at 6:31 PM, Mark Hammond wrote: > On 7/09/2009 10:50 PM, MRAB wrote: >> >> sturlamolden wrote: >>> >>> On 7 Sep, 13:53, ganesh wrote: >>> I need to use these to get the proper concurrency in my multi-threaded application without any synchronization mechanisms. >>> >>> Why will multiple interpreters give you better concurrency? You can >>> have more than one thread in the same interpreter. >>> >>> Here is the API explained: >>> >>> http://docs.python.org/c-api/init.html >>> http://www.linuxjournal.com/article/3641 >> >> CPython's GIL means that multithreading on multiple processors/cores has >> limitations. Each interpreter has its own GIL, so processor-intensive >> applications work better using the multiprocessing module than with the >> threading module. > > I believe you will find the above is incorrect - even with multiple > interpreter states you still have a single GIL. > not according to the docs. http://docs.python.org/library/multiprocessing.html : multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine. It runs on both Unix and Windows. > Mark > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 7/09/2009 10:50 PM, MRAB wrote: sturlamolden wrote: On 7 Sep, 13:53, ganesh wrote: I need to use these to get the proper concurrency in my multi-threaded application without any synchronization mechanisms. Why will multiple interpreters give you better concurrency? You can have more than one thread in the same interpreter. Here is the API explained: http://docs.python.org/c-api/init.html http://www.linuxjournal.com/article/3641 CPython's GIL means that multithreading on multiple processors/cores has limitations. Each interpreter has its own GIL, so processor-intensive applications work better using the multiprocessing module than with the threading module. I believe you will find the above is incorrect - even with multiple interpreter states you still have a single GIL. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows, CreateThread
Torsten Mohr wrote: Hi, in a python C module i may need to create a Thread to do some background observations / calculations. Are there any problems with Python doing something like this? Is there some special support on sharing data? I guess i can't call any Python functions from the thread, correct? Thanks for any hints, Torsten. Python has lots of support for threads. Look at the *thread* and *threading* modules for (respectively) low and high level access to threads, and look at the *queue *module for passing data safely between threads.While there are many issues and potential traps when thread programming. you *can* call any function from any thread at any time with any data-- threads would be a waste if that were not so. For an alternative to thread programming, you may be able to use the functionality of the *asynchat* and *asyncore* modules. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 2009-09-07, Mark Hammond wrote: >> CPython's GIL means that multithreading on multiple >> processors/cores has limitations. Each interpreter has its own >> GIL, so processor-intensive applications work better using the >> multiprocessing module than with the threading module. > > I believe you will find the above is incorrect - even with > multiple interpreter states you still have a single GIL. Please explain how multiple processes, each with a separate Python interpreter, share a single GIL. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 8/09/2009 9:16 AM, Grant Edwards wrote: On 2009-09-07, Mark Hammond wrote: CPython's GIL means that multithreading on multiple processors/cores has limitations. Each interpreter has its own GIL, so processor-intensive applications work better using the multiprocessing module than with the threading module. I believe you will find the above is incorrect - even with multiple interpreter states you still have a single GIL. Please explain how multiple processes, each with a separate Python interpreter, share a single GIL. Sorry, my mistake, I misread the original - using multiple Python processes does indeed have a GIL per process. I was referring to the 'multiple interpreters in one process' feature of Python which is largely deprecated, but if used, all 'interpreters' share the same GIL. To clarify: in a single process there will only ever be one GIL, but in multiple processes there most certainly will be multiple GILs. Apologies for the confusion... Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: IDE for python similar to visual basic
In article , Nobody wrote: >On Sun, 30 Aug 2009 10:48:24 -0700, r wrote: > >> I think a point and click GUI builder (although some may disagree) is >> actually detrimental to your programming skills. The ability to >> visualize the GUI only from the source code as you read it, is as >> important to a programmer as site reading sheet music is to a >> musician. And I like to program with the training wheels off. > >The main advantage of a GUI builder is that it helps prevent you from >hard-coding the GUI into the program. You could get the same effect by >coding a UIL/XRC/etc file manually, but a GUI builder tends to force it. A GUI builder results in hard coding the GUI. The code only resides elsewhere. > >It also allows the GUI to be edited by without requiring any programming >knowledge. This eliminates the need for the GUI designer to be familiar >with the programming language used (or any programming language), and >allows customisation by end users. This is the real argument. The code is separated into two modules. The modules are coded in different languages. All for good reason. Maybe the configuration file can be changed without recompiling the c-code. Very nice. > >Creating a GUI programmatically is almost always the wrong approach. It >tends to be adopted due to a path of least resistance, rather than any >affirmative reason. In view of the above this is not quite the correct way to put it. What I resent is that it leads to a non-professional attitude of the graphical part. Programming is over, lets now kludge some screens together. No. The graphics part has to be carefully designed, carefully tested, and carefully "written", even if it is using a graphical tool. So, yes please, *do* create a GUI "programmatically". Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. alb...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: What python can NOT do?
In article <[email protected]>, Steven D'Aprano wrote: >On Fri, 28 Aug 2009 15:37:46 -0700, qwe rty wrote: > >> i know that an interpreted language like python > >Languages are neither interpreted nor compiled. *Implementations* are >interpreted or compiled. Thanks for an excellent overview. There is this one point I don't understand: >Existing Python implementations don't give you direct access to hardware, >and bit-manipulation has a lot of overhead in Python. Numerical Surely you don't mean that 0x17 & 0xAD has more overhead than 17 + 123 So what do you mean here? > >-- >Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. alb...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: how to edit .wsgi file extebtions with IDLE on windows
On Sep 4, 6:07 am, "Gabriel Genellina" wrote: > En Sat, 29 Aug 2009 20:29:43 -0300, gert escribió: > > > > > On Aug 29, 11:16 pm, "Gabriel Genellina" > > wrote: > >> En Sat, 29 Aug 2009 17:14:14 -0300, gert > >> escribió: > >> > On Aug 29, 9:31 pm, Chris Rebert wrote: > >> >> On Sat, Aug 29, 2009 at 5:40 AM, gert wrote: > >> >> > On Aug 29, 6:43 am, "Gabriel Genellina" > >> >> > wrote: > >> >> >> En Fri, 28 Aug 2009 15:31:31 -0300, gert > >> >> escribió: > >> >> >> > I can't figure out how to enable the .py shell and syntax > >> >> >> > highlighting > >> >> >> > for .wsgi file extensions using IDLE for windows ? > > Thanks. Can you make a ispythonsource menu option in the next > > python3.x release? There are many examples of txt, xml or wsgi files > > having python parts in them. > > Please file a feature request athttp://bugs.python.org/ > I think a "This is a python file, apply syntax highlighting" menu option > is feasible, but doing the same only for part of a file is a lot harder. > http://bugs.python.org/issue6858 does not matter its trival to see which part is python -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows binaries of python in debug mode
En Mon, 07 Sep 2009 06:32:29 -0300, Gabriel Rossetti escribió: I am looking for a version of python 2.5.x compiled for windows in debug mode, but I can't find this, does anyone have a link or have a version that he/she can send me? Short answer: build it yourself. Note that you'll require *all* the C extensions you use compiled in debug mode too. This usually means that you have to recompile all of them from source. In that case, having to recompile Python itself doesn't impose much additional work, and you are free of compiler mismatch issues. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Flowcharting in Python?
On Tuesday 08 September 2009 00:09, Grant Edwards wrote: > Have you looked at Skencil (nee Sketch)? It's a > vector/object-oriented drawing program written in Python: > > http://www.skencil.org/ > > It's not really optimized for flowcharts or block diagrams > (IIRC, it doens't have any concept of connecting arcs between > polygrams), but you might be able to extend it. Or maybe Dia is worth looking at, since it is aimed at diagram creation: http://live.gnome.org/Dia/Python >> I'm beginning to think I'll have to create something from scratch. > > I wouldn't think you'd have to start from scratch. You should > at least use one of the GUI frameworks that has some sort of > canvas widget. PyQt4 contains an example called diagramscene.py which does simple flowcharting. It might be useful to look at it to get some ideas. Personally, I had thought about adapting it to create statecharts. David -- http://mail.python.org/mailman/listinfo/python-list
expy 0.1.3 released!
Hi, This is to announce the release of expy 0.1.3 Now this release support class members/fields besides instance members/fields of extension types. What is expy? -- expy is an expressway to extend Python! For more details on expy: http://expy.sf.net/ Thanks! Yingjie -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
PythonAB: > I dont want to register with a google account, > is there any way to use a non-gmail account? A Google account does not mean you have to use gmail. The Google account is used to handle your interaction with Google services and can be used in conjunction with arbitrary email accounts. Just create a Google account and set the email address to your preferred address. Neil -- http://mail.python.org/mailman/listinfo/python-list
**** Sweet Teen TITS!! BOOBS VIDEOS HI RES PHOTOS !!!
Download http://centraltits.blogspot.com/2009/09/where-can-beginner-start-investing-and.html Free videos high resolution photos and much more. You know what to do! Free Downloads! -- http://mail.python.org/mailman/listinfo/python-list
Re: **** Sweet Teen TITS!! BOOBS VIDEOS HI RES PHOTOS !!!
On Sep 7, 8:31 pm, Kevin Katovic wrote: > Downloadhttp://centraltits.blogspot.com/2009/09/where-can-beginner-start-inve... > Free videos high resolution photos and much more. You know what to > do! Free Downloads! Sold! Thanks everyone. -- http://mail.python.org/mailman/listinfo/python-list
Import Problem - Please help
I am trying to learn NLP with Python and am getting the following error when trying to do an import statement: >>> import nltk >>> import re >>> from nltk_lite.utilities import re_show Traceback (most recent call last): File "", line 1, in ImportError: No module named nltk_lite.utilities I have installed nltk already and have a problem where I need to remove vowels from text. I think I need this module to complete it. Any help would be much appreciated. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Problem - Please help
On Sep 7, 5:40 pm, "newb.py" wrote: > I am trying to learn NLP with Python and am getting the following > error when trying to do an import statement: > > >>> import nltk > >>> import re > >>> from nltk_lite.utilities import re_show > > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named nltk_lite.utilities > > I have installed nltk already and have a problem where I need to > remove vowels from text. I think I need this module to complete it. > > Any help would be much appreciated. > > Thanks. My version of Python is 2.6.2. It seems that might make a difference here, but I can't figure it out. Again, any help would be fantastic. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
unicode + xml
Hello, I am trying to do the following: - read list of folders in a specific directory: os.listdir() - some folders have Japanese characters - post list of folders as xml to a web server: I used content-type 'text/xml' and I use '' to start the xml data. - on the server side (Django), I get the data using post_data and I use minidom.parseString() to parse it. I get an exception because of the following in the xml for one of the folder name: '/ufffdX/ufffd^/ufffd[/ufffdg /ufffd/ufffd/ufffdj/ufffd/ufffd/ufffd[' The weird thing is that I see 5 bytes for each unicode character: ie: /ufffdX Should I format the data differently inside the xml so minidom is happy ? Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: First release of pyfsevents
In article , Nicolas Dumazet wrote: >On Sep 3, 10:33=A0pm, [email protected] (Aahz) wrote: >> >> I'm curious why you went with FSEvents rather than kqueue. My company >> discovered that FSEvents is rather coarse-grained: it only tells you that >> there has been an event within a directory, it does *not* tell you >> anything about the change! > >It depends what you want to do with your events. In my case, knowing >that an event occurred in a directory is sufficient because I already >know the state of the directory. If you look in the examples/ folder, >(watcher) you'll find that with very little work, you can maintain a >directory snapshot in memory and compare it against the new state of >the directory to know exactly what happened, when necessary. Thanks! >kqueue has the limitation that kern.kq_calloutmax is usually set >at 4096. Meaning that one could not use this on a big (Mercurial) >repository with 5k files. FSEvents on the other hand saves us the >trouble to have to register each file individually. Also, I am not >quite sure if we can use kqueue to register a directory, to be warned >when a file is created in this directory. %(obscenity)s I didn't realize that you had to register each file individually with kqueue. We were hoping to avoid having to write watcher code because that is not reliable for renames (especially multiple renames in quick succession). Maybe we'll try using /dev/fsevents directly -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: possible attribute-oriented class
08-09-2009 o 02:15:10 Steven D'Aprano wrote: On Mon, 7 Sep 2009 09:37:35 am Jan Kaliszewski wrote: 06-09-2009 o 20:20:21 Ethan Furman wrote: > ... I love being able to type > >current_record.full_name == last_record.full_name > > instead of > >current_record['full_name'] == last_record['full_name'] Me too, and I suppose many people too... The latter: * makes your code less readable if there is high density of such expressions; * makes typing much more strenuous/irritating -- what is not very important in case of advanced development (when time of typing is short in relation to time of thinking/reading/testing) but becomes quite important in case of scripting (which is still important area of Python usage). If you have a large number of such expressions, what's wrong with this? a['xyz'] = something['blablabla'] + somethingelse['foobar'] b['ababababa'] += afun(bobo['dodo']['kookoo'] * pofopofo['gh'][0]['a']) cupu['abc'] = (kukumunu['bo'], kukumunu['kuu'].mbmbmb['lalala']) a.xyz = something.blablabla + somethingelse.foobar b.ababababa += afun(bobo.dodo.kookoo * pofopofo.gh[0].a) cupu.abc = (kukumunu.bo, kukumunu.kuu.mbmbmb.lalala) For me the latter is definitely easier to read and understand. FNAME = "full_name" # Define the string in one place only. current_record[FNAME] == last_record[FNAME] # Use it in many places. Not only is it shorter to use, but it's easy to change the key "full_name" to (say) "complete_name" or "volledige_naam" with one edit, and without mistakenly changing some other string which just happens to match the key. You are right, but it's a bit different story... I don't say that attr access is always better than key access -- but only that sometimes it is. (I don't know about others, but when I'm first working on a piece of code, and before I settle on an API or database schema, I often change field names two or three times before I settle in on the final version.) Me too! :) In any case, while I accept that this is sometimes useful, I also think that it's a something which is simple enough to add to your classes when necessary with just a few lines -- all you really need are the __*attr__ methods, everything else is superfluous. If you're doing this a lot, avoid boilerplate with a class decorator. Here's an untested minimalistic version which probably does everything necessary: def add_attr(cls): """Class decorator which adds attribute access to mappings.""" def __getattr__(self, name): return self[name] def __setattr__(self, name, value): self[name] = value def __delattr__(self, name): del self[name] for func in (__getattr__, __setattr__, __delattr__): setattr(cls, func.__name__, func) return cls I'd add to it also dict-like iteration (__iter__(), _keys(), _values(), _items()) and __str__ adjusted to nice nested representation (like in some posts in this thread, e.g. my proposition). Fields of an object (attributes) and keys of a mapping are generally for different purposes, and I'm not sure we should encourage people to conflate the two. I think this belongs in the cookbook, not the standard library. I think it depends how often people need to implement such boiler-plate code for themselves. Now I see that this thread is not very popular, so indeed maybe you are right... Though it'd be nice to have OOTB such a factory in `collections` module... Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list
Re: IDE for python similar to visual basic
On Sep 7, 6:56 pm, Albert van der Horst wrote: > In article , > > Nobody wrote: > >On Sun, 30 Aug 2009 10:48:24 -0700, r wrote: > > >> I think a point and click GUI builder (although some may disagree) is > >> actually detrimental to your programming skills. The ability to > >> visualize the GUI only from the source code as you read it, is as > >> important to a programmer as site reading sheet music is to a > >> musician. And I like to program with the training wheels off. > > >The main advantage of a GUI builder is that it helps prevent you from > >hard-coding the GUI into the program. You could get the same effect by > >coding a UIL/XRC/etc file manually, but a GUI builder tends to force it. > > A GUI builder results in hard coding the GUI. The code only resides > elsewhere. +1 > >It also allows the GUI to be edited by without requiring any programming > >knowledge. This eliminates the need for the GUI designer to be familiar > >with the programming language used (or any programming language), and > >allows customisation by end users. and this is why M$ interfaces suck eggs! This whole "let's just slap together something that works even if kludgy" attitude begets the horrible UI's of which i speak. Are you saying that programmers have no ability to design elegant UI's? Or are you saying GUI's are not *that* important? > What I resent is that it leads to a non-professional attitude > of the graphical part. Programming is over, lets now kludge > some screens together. No. The graphics part has to be carefully > designed, carefully tested, and carefully "written", even if it > is using a graphical tool. So, yes please, *do* create a GUI > "programmatically". > > Groetjes Albert Agreed! You *must* get up-close-and-personal with the GUI code. You know, in the past i would write the logic first and then fit the GUI to the code, not any more!. Now I design the GUI first, then write the code to complement it. Maybe i'm just nuts, but i thought GUI's where targeted at "non-technical" end users, not the enlightened few? get_enlightened(http://jjsenlightenments.blogspot.com/) -- http://mail.python.org/mailman/listinfo/python-list
SPAM
On Sep 7, 5:37 pm, MrBally wrote: > On Sep 7, 8:31 pm, Kevin Katovic > wrote: > > > Downloadhttp://centraltits.blogspot.com/2009/09/where-can-beginner-start-inve... > > Free videos high resolution photos and much more. You know what to > > do! Free Downloads! > > Sold! Thanks everyone. spam -- http://mail.python.org/mailman/listinfo/python-list
Re: SPAM
In article , TBK says... > >On Sep 7, 5:37=A0pm, MrBally wrote: >> On Sep 7, 8:31=A0pm, Kevin Katovic >> wrote: >> >> > Downloadhttp://centraltits.blogspot.com/2009/09/where-can-beginner-star= >t-inve... >> > Free videos high resolution photos and much more. =A0You know what to >> > do! Free Downloads! >> >> Sold! Thanks everyone. > >spam Thank God you pointed this out to everyone. We would not have known otherwise. Asswipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 2009-09-07, Mark Hammond wrote: > Sorry, my mistake, I misread the original - using multiple > Python processes does indeed have a GIL per process. I was > referring to the 'multiple interpreters in one process' > feature of Python which is largely deprecated, but if used, > all 'interpreters' share the same GIL. Oh yea, i had forgotten you could do that. I can see how one could have interpretted the "multiple instances" references to mean multiple interpreter instances within a process. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Problem - Please help
In article <[email protected]>, "newb.py" wrote: > On Sep 7, 5:40 pm, "newb.py" wrote: > > I am trying to learn NLP with Python and am getting the following > > error when trying to do an import statement: > > > > >>> import nltk > > >>> import re > > >>> from nltk_lite.utilities import re_show > > > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named nltk_lite.utilities Guessing from the current documentation, try replacing the third line with: >>> from nltk.util import re_show -- Ned Deily, [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: possible attribute-oriented class
On Mon, Sep 7, 2009 at 6:02 PM, Jan Kaliszewski wrote: ... > > I think it depends how often people need to implement such boiler-plate > code for themselves. Now I see that this thread is not very popular, so > indeed maybe you are right... Though it'd be nice to have OOTB such > a factory in `collections` module... > ... How about, if this is not judged to be popular enough to become part of core or other standard module, at least put a version into a FAQ for easy future access by those of us that have a use for it? The suggestions here (and past versions) are much better than my first do-it-myself version - a standard peer-reviewed recipe would have been very nice to find. -- http://mail.python.org/mailman/listinfo/python-list
Re: Query screen resolution?
> If it's a GUI app, you ask the GUI toolkit which you're using. Heh, I suppose you're right :) -- http://mail.python.org/mailman/listinfo/python-list
Re: First release of pyfsevents
On 12:57 am, [email protected] wrote: In article [email protected]>, Nicolas Dumazet wrote: On Sep 3, 10:33=A0pm, [email protected] (Aahz) wrote: I'm curious why you went with FSEvents rather than kqueue. My company discovered that FSEvents is rather coarse-grained: it only tells you that there has been an event within a directory, it does *not* tell you anything about the change! It depends what you want to do with your events. In my case, knowing that an event occurred in a directory is sufficient because I already know the state of the directory. If you look in the examples/ folder, (watcher) you'll find that with very little work, you can maintain a directory snapshot in memory and compare it against the new state of the directory to know exactly what happened, when necessary. Thanks! kqueue has the limitation that kern.kq_calloutmax is usually set at 4096. Meaning that one could not use this on a big (Mercurial) repository with 5k files. FSEvents on the other hand saves us the trouble to have to register each file individually. Also, I am not quite sure if we can use kqueue to register a directory, to be warned when a file is created in this directory. %(obscenity)s I didn't realize that you had to register each file individually with kqueue. We were hoping to avoid having to write watcher code because that is not reliable for renames (especially multiple renames in quick succession). Maybe we'll try using /dev/fsevents directly Just a guess, but since the kqueue interface is based on file descriptors, not on file names, following renames reliably shouldn't be a problem with it. If someone knows about this for sure though, it'd be nice to hear about it. :) All of the kqueue documentation I've seen has been rather incomplete. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Class variable inheritance
I've just found out that a subclass shares the class variables of its superclass until it's instantiated for the first time, but not any more afterwards: Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... n = 0 ... def __init__(self): ... type(self).n += 1 >>> class B(A): ... pass >>> A.n, B.n (0, 0) >>> (A().n, A.n, B.n), (A().n, A.n, B.n), (B().n, A.n, B.n) ((1, 1, 1), (2, 2, 2), (3, 2, 3)) >>> (A().n, A.n, B.n), (A().n, A.n, B.n), (B().n, A.n, B.n) ((3, 3, 3), (4, 4, 3), (4, 4, 4)) >>> (A().n, A.n, B.n), (A().n, A.n, B.n), (B().n, A.n, B.n) ((5, 5, 4), (6, 6, 4), (5, 6, 5)) This makes no sense to me at all. Could it possibly be a bug? -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
My application is a TCP server having multiple client connectons. C++ PTHREADS are for each connected socket and the message received on the socket is evaluated by python functions. If I use only one process level python interpreter, then every thread has to lock the GIL & so blocking the other threads from executing the python code even if it is not the same python function that locking thread is calling. -- That's why I tried using python interpreters per thread. But that also required GIL locking & so cannot be used. -- I cannot use python threads inside the Pyton intrepreter because then I will have to have some mechanism for communiaction between C++ Pthreads with these python threads. I think there is no way that we can achieve this because of the GIL being a process level state. Least I can do is have one python interpreter initialized in main thread and lock the GIL in every thread for python calls. -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Problem - Please help
On Sep 7, 6:55 pm, Ned Deily wrote: > In article > <[email protected]>, > > "newb.py" wrote: > > On Sep 7, 5:40 pm, "newb.py" wrote: > > > I am trying to learn NLP with Python and am getting the following > > > error when trying to do an import statement: > > > > >>> import nltk > > > >>> import re > > > >>> from nltk_lite.utilities import re_show > > > > Traceback (most recent call last): > > > File "", line 1, in > > > ImportError: No module named nltk_lite.utilities > > Guessing from the current documentation, try replacing the third line > with: > > >>> from nltk.util import re_show > > -- > Ned Deily, > [email protected] Fantastic. Thanks so much! -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Mon, 07 Sep 2009 19:21:28 -0700, Henry 'Pi' James wrote: > I've just found out that a subclass shares the class variables String variables are strings. Int variables are ints. Float variables are floats. List variables are lists. Class variables are classes. Classes are first-class objects in Python. Perhaps you mean class attributes? > of its > superclass until it's instantiated for the first time, but not any more > afterwards: ... > This makes no sense to me at all. Could it possibly be a bug? You have misinterpreted what you have seen, and if there's a bug, it's in your code. When you retrieve an attribute, Python first looks for instance attributes, then class attributes, then attributes attached to superclasses. When you assign to an attribute, Python conceptually uses the exact same "search path", except that instance assignment always succeeds. (Well, almost -- but if it fails, you get an exception.) So in practice: x = obj.whatever may return the contents of an instance attribute "whatever", a class attribute, or an attribute of a superclass. But: obj.whatever = x always attempts to store x as an instance attribute, because there's no way for Python to read your mind and know that you mean a class attribute unless you say so explicitly. This attempt will either succeed, or it will raise an exception. Python doesn't try writing further along the hierarchy of instance/class/superclass(es). If you wish to write to a class attribute, you have to explicitly say so: obj.__class__.whatever = x Your other misunderstanding relates to augmented assignment: x += 1 does not modify x in place, it is *exactly* equivalent to: x = x + 1 Given the rules of attribute access, obj.whatever += 1 is exactly equivalent to: obj.whatever = obj.whatever + 1 The right hand attribute access finds a class attribute, and the left hand one sets an instance attribute. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: What python can NOT do?
On Tue, 08 Sep 2009 00:09:26 +, Albert van der Horst wrote: >>Existing Python implementations don't give you direct access to >>hardware, and bit-manipulation has a lot of overhead in Python. >>Numerical > > Surely you don't mean that >0x17 & 0xAD > has more overhead than >17 + 123 > So what do you mean here? What I mean is that bit-manipulation in low-level languages like C is very close to the metal, and hence very efficient. In Python, *all* operations (including bit-manipulation and arithmetic) has the overhead of the Python virtual machine. You won't notice the difference if you're just ANDing a handful of numbers, but if you're doing millions of them (say, you're doing industrial-strength encryption) you certainly will. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Mon, Sep 7, 2009 at 7:21 PM, Henry 'Pi' James wrote: > I've just found out that a subclass shares the class variables of its > superclass until it's instantiated for the first time, but not any > more afterwards: > > Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. class A: > ... n = 0 > ... def __init__(self): > ... type(self).n += 1 class B(A): > ... pass > This makes no sense to me at all. Could it possibly be a bug? Makes sense to me. To step through what's happening: >>> A.n, B.n (0, 0) Here, the lookup on B.n fails (that is, B itself has no variable n), and thus falls back to A.n Thus, at this point, the expressions `A.n` and `B.n` are equivalent. >>> (A().n, A.n, B.n) (1, 1, 1) A.__init__() gets called, incrementing A.n; again, B.n falls back to A.n >>> (A().n, A.n, B.n) (2, 2, 2), >>> (B().n, A.n, B.n) (3, 2, 3) A.__init__() gets called since B did not define one of its own and this inherited A's. Therein, type(self) evaluates to B (not A as before). B.n += 1 is in this case equivalent to: B.n = B.n +1 Evaluating the right side, B.n falls back A.n once again, and we add 1. Now the assignment takes place, creating a new variable B.n, *separate* from A.n From hereon in, lookups of B.n don't fall back to A.n since B now has its own variable 'n'. Thus, the values of A.n and B.n differ and the expressions now refer to 2 distinct variables. The rest falls out from this and is left as an exercise for the reader. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to data files without hardcoding paths?
En Sun, 06 Sep 2009 10:44:38 -0300, Timothy Madden escribió: Matthew Wilson wrote: When a python package includes data files like templates or images, what is the orthodox way of referring to these in code? I also came across pkg_resources, and that seems to work, but I don't think I understand it all yet. sys.path[0] should give you the path to your script. By reading the documentation I would say it would give the path to the first script passed to the interpreter at launch, but after using it I find it also gives the current script path inside an imported file. So I use it to group the script files in my application into subdirectories, and import them as necessary from there. No, I think you got it wrong. sys.argv[0] is the name of the script being executed; you can get its full path using os.path.abspath(sys.argv[0]) sys.path[0] is the directory containing the script being executed right when the program starts. Later, any module is free to add and remove entries from sys.path, so one should not rely on sys.path[0] being that specific directory. What you refer as "script files" are actually modules, and they're imported, not executed. There is only one script being executed, the one named in the command line (either as `python scriptname.py` or `scriptname.py` or just `scriptname` or by double-clicking scriptname.py) My app works regardless of the current working directory, and can import scripts and load icons from its various subdirectories. Still I would like to know why it works in imported scripts, since the doc page says sys.path[0] is the path to the script that caused the interpreter to launch. What would that mean ? The script that is being executed, scriptname.py in the example above. Even if you later import module `foo` from package `bar`, sys.argv[0] doesn't change. To determine the directory containing the main script being executed, put these lines near the top of it: import os,sys main_directory = os.path.dirname(os.path.abspath(sys.argv[0])) You may locate other files relative to that directory. But that doesn't work if some components aren't actually on the filesystem (egg files, zipped libraries, or programs deployed using py2exe or similar). I prefer to use pkgutil.get_data(packagename, resourcename) because it can handle those cases too. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
