Attaching to a Python Interpreter a la Tcl
Hello, Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my app. The coolest thing was however, I was able to attach to the interpreter (built in to my app) via a tcl shell in which I could type in regular tcl code which would be interpreted by the interpreter of my application. Naturally, it was possible to call tcl functions of my applications. Some kind of rapid RPC. Is this also possible with python ? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Terminating a thread from the parent
Hello, I have an app with embedded Python. Python scripts create their own threads and I need to terminate these threads at the point where the user wants to leave the application. I use threading.Thread as base classes. I have tried to use call the join method of the python thread objects from C++. But although the call succeeds, the threads don't exit. What is the proper way of doing this ? (e.g. how does the python shell do this ? ) Thanks in advance, Devrim. -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminating a thread from the parent
I appreciate your posts guys. It answers my questions and I like the idea of overriding join method. I will use this one. -- http://mail.python.org/mailman/listinfo/python-list
Windows Installer with Debug Dlls and Libs
Hello, I have a problem with python builds since some time. On windows, it is not a good idea to link your debug build to release builds of libs and dlls. But python installer gives you only release builds. So I need to build python myself, no problem, but I have never managed to setup python like the way installer does. (I guess it does some registry and env var tricks.) For example, - it is not possible to install extensions like wxPython, because the wxPython installer doesn't like my custom installation - WinCVS never gets my custom python installation and so on. Can you give me any hints on this nasty problem ? Thanks, DE -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows Installer with Debug Dlls and Libs
Thanks Trent. That's good news. Does ActivateState produce the debug package everytime they build a python release ? If this is a policy at ActivateState, I will feel myself on better grounds :) Ciao, DE -- http://mail.python.org/mailman/listinfo/python-list
Indentation for code readability
Hello, Here is what I do in C++ and can not right now in python : pushMatrix() { drawStuff(); pushMatrix(); { drawSomeOtherStuff() } popMatrix(); } popMatrix(); The curly brackets have no functional meaning but increase the readability significantly. I want to be able to do the same thing in python. Since curly brackets are not available and indenting without an if or while conditional doesn't work, I have started to question if this is possible in python at all. Any ideas ? MDE -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation for code readability
Thanks Peter. This sounds like to right solution for my case, because in addition to indentation, I can automate push and pop. I'll investigate this further. I appreciate. -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation for code readability
> > I don't understand why you are indenting > the function calls. What does the > indentation and spacing signify? The indentation of function calls increases readability not in the sense that it is easier to decrypt the code, but rather it is analogous to the coordinate system transformations these matrix push and pop calls perform.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation for code readability
Thanks Duncan. I guess you and Peter have been typing in the same minute :) It really looks like a good solution, I wasn't aware this with statement in Python. I can imagine the context handler coming handy in other cases too. Devrim -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation for code readability
> > > The curly brackets have no functional meaning... > > "Curly brackets have no functional meaning"? Surely you must be > thinking of C, but not C++. Some of the most powerful idioms (idia?) > of C++ make use of functionality that runs when a closing bracket > causes local variables to fall out of scope. In fact, this technique > is crucial to writing exception-safe code. The curly brackets have no functional meaning in the scope of the example I have written in my original mail. I usually ask C++ memory management issues in in the relevant newsgroup :) -- http://mail.python.org/mailman/listinfo/python-list
Re: "py" command for Linux and Mac?
On 2022-05-12, Mats Wichmann wrote: > On 5/12/22 10:25, Dan Stromberg wrote: >> Hi folks. >> >> I heard there's a Windows-like "py" command for Linux (and Mac?). >> >> I'm finally getting to porting a particular project's Python 2.7 code to >> 3.x, and one of the first steps will probably be changing a lot of "python2 >> script.py" to use #!/usr/bin/env python2 and chmod +x. Then we can update >> the scripts one at a time to use #!/usr/bin/env python3. >> >> However, would this be Linux-and-Mac-only? I'm not at all sure this code >> will ever move to Windows, but in case it does, would a "py" command work >> on all 3 if I use #!/usr/bin/env py? > > The py command (python lanucher) respects shebang lines. Linux by itself respects shebang lines, so you don't need a separate launcher program. Just put e.g.: #! /usr/bin/env python at the top of your Python file. -- In the beginning there was darkness and the darkness was without form and void. And in addition to the darkness there was also me. And I moved upon the face of the darkness and I saw that I was alone. ... ... ... Let there be light. [Bomb 20; John Carpenter's Dark Star - 1974] -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-07, Dave wrote: > Hi, > > I’m new to Python and have a simple problem that I can’t seem to find the > answer. > > I want to test the first two characters of a string to check if the are > numeric (00 to 99) and if so remove the fist three chars from the string. > > Example: if “05 Trinket” I want “Trinket”, but “Trinket” I still want > “Trinket”. I can’t for the life of work out how to do it in Python? s[3:] if s[0:2].isdigit() else s > All the Best > Dave > -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-07, Stefan Ram wrote: > Dave writes: >>Example: if "05 Trinket" I want "Trinket" > > We're not supposed to write complete solutions, Okay, wasn't aware of this group policy; will keep it in mind. -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-07, Dave wrote: > Thanks a lot for this! isDigit was the method I was looking for and couldn’t > find. > > I have another problem related to this, the following code uses the code you > just sent. I am getting a files ID3 tags using eyed3, this part seems to work > and I get expected values in this case myTitleName (Track name) is set to > “Deadlock Holiday” and myCompareFileName is set to “01 Deadlock Holiday” > (File Name with the Track number prepended). The is digit test works and > myCompareFileName is set to “Deadlock Holiday”, so they should match, right? > > However the if myCompareFileName != myTitleName always gives a mismatch! What > could cause two string that look the fail to not match properly? Possibly leading or trailing spaces, or upper/lower case differences? > myCompareFileName = myFile > if myCompareFileName[0].isdigit() and myCompareFileName[1].isdigit(): > myCompareFileName = myCompareFileName[3:] > > if myCompareFileName != myTitleName: > print('File Name Mismatch - Artist: ',myArtistName,' Album: > ',myAlbumName,' Track:',myTitleName,' File: ',myFile) > Thanks a lot > Dave > >> On 7 Jun 2022, at 21:58, De ongekruisigde >> wrote: >> >> On 2022-06-07, Dave wrote: >>> Hi, >>> >>> I’m new to Python and have a simple problem that I can’t seem to find the >>> answer. >>> >>> I want to test the first two characters of a string to check if the are >>> numeric (00 to 99) and if so remove the fist three chars from the string. >>> >>> Example: if “05 Trinket” I want “Trinket”, but “Trinket” I still want >>> “Trinket”. I can’t for the life of work out how to do it in Python? >> >> >> s[3:] if s[0:2].isdigit() else s >> >> >>> All the Best >>> Dave >>> >> >> -- >> You're rewriting parts of Quake in *Python*? >> MUAHAHAHA >> -- >> https://mail.python.org/mailman/listinfo/python-list > -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-08, Christian Gollwitzer wrote: > Am 07.06.22 um 21:56 schrieb Dave: >> It depends on the language I’m using, in Objective C, I’d use isNumeric, >> just wanted to know what the equivalent is in Python. >> > > Your problem is also a typical case for regular expressions. You can > create an expression for "starts with any number of digits plus optional > whitespace" and then replace this with nothing: Regular expressions are overkill for this and much slower than the simple isdigit based solution. >> chris@linux-tb9f:~> ipython >> Python 3.6.15 (default, Sep 23 2021, 15:41:43) [GCC] >> Type 'copyright', 'credits' or 'license' for more information >> IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help. >> >> In [1]: import re >> >> >> >> In [2]: s='05 Trinket' >> >> >> >> In [3]: re.sub(r'^\d+\s*', '', s) >> >> >> Out[3]: 'Trinket' >> > > If it doesn't match, it will do nothing: > >> In [4]: s='Es geht los' >> >> >> >> In [5]: re.sub(r'^\d+\s*', '', s) >> >> >> Out[5]: 'Es geht los' > > Some people on this list don't like regexes but for tasks like this they > are made and working well. Regular expressions are indeeed extremely powerful and useful but I tend to avoid them when there's a (faster) normal solution. > ^ is "starts with" > \d is any digit > \s is any space > + is at least one > * is nothing or one of > > Christian -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to replace characters in a string?
On 2022-06-08, Dave wrote: > Hi All, > > I decided to start a new thread as this really is a new subject. > > I've got two that appear to be identical, but fail to compare. After getting > the ascii encoding I see that they are indeed different, my question is how > can I replace the \u2019m with a regular single quote mark (or apostrophe)? You're not facing this alone: https://changelog.complete.org/archives/9938-the-python-unicode-mess Perhaps useful insights can be found at: https://realpython.com/python-encodings-guide/ > +++ -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-08, dn wrote: > On 08/06/2022 10.18, De ongekruisigde wrote: >> On 2022-06-08, Christian Gollwitzer wrote: >>> Am 07.06.22 um 21:56 schrieb Dave: >>>> It depends on the language I’m using, in Objective C, I’d use isNumeric, >>>> just wanted to know what the equivalent is in Python. >>>> >>> >>> Your problem is also a typical case for regular expressions. You can >>> create an expression for "starts with any number of digits plus optional >>> whitespace" and then replace this with nothing: >> >> Regular expressions are overkill for this and much slower than the >> simple isdigit based solution. > > ... > >> Regular expressions are indeeed extremely powerful and useful but I tend >> to avoid them when there's a (faster) normal solution. > > Yes, simple solutions are (likely) easier to read. Depending on the problem a regular expression may be the much simpler solution. I love them for e.g. text parsing and use them all the time. Unrivaled when e.g. parts of text have to be extracted, e.g. from lines like these: root:x:0:0:System administrator:/root:/run/current-system/sw/bin/bash dhcpcd:x:995:991::/var/empty:/run/current-system/sw/bin/nologin nm-iodine:x:996:57::/var/empty:/run/current-system/sw/bin/nologin avahi:x:997:996:avahi-daemon privilege separation user:/var/empty:/run/current-system/sw/bin/nologin sshd:x:998:993:SSH privilege separation user:/var/empty:/run/current-system/sw/bin/nologin geoclue:x:999:998:Geoinformation service:/var/lib/geoclue:/run/current-system/sw/bin/nologin Compare a regexp solution like this: >>> g = re.search(r'([^:]*):([^:]*):(\d+):(\d+):([^:]*):([^:]*):(.*)$' , s) >>> print(g.groups()) ('geoclue', 'x', '999', '998', 'Geoinformation service', '/var/lib/geoclue', '/run/current-system/sw/bin/nologin') to the code one would require to process it manually, with all the edge cases. The regexp surely reads much simpler (?). > RegEx-s are more powerful (and well worth learning for this reason), but > are only 'readable' to those who use them frequently. > > Has either of you performed a timeit comparison? No need: the isdigit solution doesn't require the overhead of a regex processor. -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-08, Dave wrote: > I hate regEx and avoid it whenever possible, I’ve never found something that > was impossible to do without it. I love regular expressions and use them where appropriate. Saves tons of code and is often much more readable than the pages of code required to do the same. -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-08, Christian Gollwitzer wrote: > Am 07.06.22 um 23:01 schrieb Christian Gollwitzer: > >>> In [3]: re.sub(r'^\d+\s*', '', s) Out[3]: 'Trinket' >>> > > that RE does match what you intended to do, but not exactly what you > wrote in the OP. that would be '^\d\d.' start with exactly two digits > followed by any character. Indeed but then I'd like '\d{2}' even better. > Christian -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-08, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: > On 2022-06-08 at 08:07:40 -0000, > De ongekruisigde wrote: > >> Depending on the problem a regular expression may be the much simpler >> solution. I love them for e.g. text parsing and use them all the time. >> Unrivaled when e.g. parts of text have to be extracted, e.g. from lines >> like these: >> >> root:x:0:0:System administrator:/root:/run/current-system/sw/bin/bash >> dhcpcd:x:995:991::/var/empty:/run/current-system/sw/bin/nologin >> nm-iodine:x:996:57::/var/empty:/run/current-system/sw/bin/nologin >> avahi:x:997:996:avahi-daemon privilege separation >> user:/var/empty:/run/current-system/sw/bin/nologin >> sshd:x:998:993:SSH privilege separation >> user:/var/empty:/run/current-system/sw/bin/nologin >> geoclue:x:999:998:Geoinformation >> service:/var/lib/geoclue:/run/current-system/sw/bin/nologin >> >> Compare a regexp solution like this: >> >> >>> g = re.search(r'([^:]*):([^:]*):(\d+):(\d+):([^:]*):([^:]*):(.*)$' , s) >> >>> print(g.groups()) >> ('geoclue', 'x', '999', '998', 'Geoinformation service', >> '/var/lib/geoclue', '/run/current-system/sw/bin/nologin') >> >> to the code one would require to process it manually, with all the edge >> cases. The regexp surely reads much simpler (?). > > Uh... > > >>> import pwd # https://docs.python.org/3/library/pwd.html > >>> [x for x in pwd.getpwall() if x[0] == 'geoclue'] > [pwd.struct_passwd(pw_name='geoclue', pw_passwd='x', pw_uid=992, > pw_gid=992, pw_gecos='Geoinformation service', pw_dir='/var/lib/geoclue', > pw_shell='/sbin/nologin')] Yeah... Well, it was just an example and it must be clear by now I'm not a Python programmer. -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
On 2022-06-08, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: > On 2022-06-09 at 04:15:46 +1000, > Chris Angelico wrote: > >> On Thu, 9 Jun 2022 at 04:14, <2qdxy4rzwzuui...@potatochowder.com> wrote: >> > >> > On 2022-06-09 at 03:18:56 +1000, >> > Chris Angelico wrote: >> > >> > > On Thu, 9 Jun 2022 at 03:15, <2qdxy4rzwzuui...@potatochowder.com> wrote: >> > > > >> > > > On 2022-06-08 at 08:07:40 -, >> > > > De ongekruisigde wrote: >> > > > >> > > > > Depending on the problem a regular expression may be the much simpler >> > > > > solution. I love them for e.g. text parsing and use them all the >> > > > > time. >> > > > > Unrivaled when e.g. parts of text have to be extracted, e.g. from >> > > > > lines >> > > > > like these: >> > > > > >> > > > > root:x:0:0:System >> > > > > administrator:/root:/run/current-system/sw/bin/bash >> > > > > dhcpcd:x:995:991::/var/empty:/run/current-system/sw/bin/nologin >> > > > > nm-iodine:x:996:57::/var/empty:/run/current-system/sw/bin/nologin >> > > > > avahi:x:997:996:avahi-daemon privilege separation >> > > > > user:/var/empty:/run/current-system/sw/bin/nologin >> > > > > sshd:x:998:993:SSH privilege separation >> > > > > user:/var/empty:/run/current-system/sw/bin/nologin >> > > > > geoclue:x:999:998:Geoinformation >> > > > > service:/var/lib/geoclue:/run/current-system/sw/bin/nologin >> > > > > >> > > > > Compare a regexp solution like this: >> > > > > >> > > > > >>> g = >> > > > > re.search(r'([^:]*):([^:]*):(\d+):(\d+):([^:]*):([^:]*):(.*)$' , s) >> > > > > >>> print(g.groups()) >> > > > > ('geoclue', 'x', '999', '998', 'Geoinformation service', >> > > > > '/var/lib/geoclue', '/run/current-system/sw/bin/nologin') >> > > > > >> > > > > to the code one would require to process it manually, with all the >> > > > > edge >> > > > > cases. The regexp surely reads much simpler (?). >> > > > >> > > > Uh... >> > > > >> > > > >>> import pwd # https://docs.python.org/3/library/pwd.html >> > > > >>> [x for x in pwd.getpwall() if x[0] == 'geoclue'] >> > > > [pwd.struct_passwd(pw_name='geoclue', pw_passwd='x', pw_uid=992, >> > > > pw_gid=992, pw_gecos='Geoinformation service', >> > > > pw_dir='/var/lib/geoclue', pw_shell='/sbin/nologin')] >> > > >> > > That's great if the lines are specifically coming from your system's >> > > own /etc/passwd, but not so much if you're trying to compare passwd >> > > files from different systems, where you simply have the files >> > > themselves. >> > >> > In addition to pwent to get specific entries from the local password >> > database, POSIX has fpwent to get a specific entry from a stream that >> > looks like /etc/passwd. So even POSIX agrees that if you think you have >> > to process this data manually, you're doing it wrong. Python exposes >> > neither functon directly (at least not in the pwd module or the os >> > module; I didn't dig around or check PyPI). >> >> So.. we can go find some other way of calling fpwent, or we can >> just parse the file ourselves. It's a very VERY simple format. > > If you insist: > > >>> s = > 'nm-iodine:x:996:57::/var/empty:/run/current-system/sw/bin/nologin' > >>> print(s.split(':')) > ['nm-iodine', 'x', '996', '57', '', '/var/empty', > '/run/current-system/sw/bin/nologin'] > > Hesitantly, because this is the Python mailing list, I claim (a) ':' is > simpler than r'([^:]*):([^:]*):(\d+):(\d+):([^:]*):([^:]*):(.*)$', and > (b) string.split covers pretty much the same edge cases as re.search. Ah, but you don't catch the be numeric of fields (0-based) 2 and 3! But agreed, it's not the best of examples. -- You're rewriting parts of Quake in *Python*? MUAHAHAHA -- https://mail.python.org/mailman/listinfo/python-list
Re: WHAT THE ERROR ON MY CODE???
On 2022-06-28, Chris Angelico wrote: > On Wed, 29 Jun 2022 at 01:37, נתי שטרן wrote: >> headers["Authorization"] = "Basic >> YjMwMzcwODY3NTUzNDMwNTg5NzA2MjkyNDFmMDE1YWY6VjNKYTk2Y1F4RTFzeTdYbzRnbkt0a2k1djhscXUyU01oSE5VWUwwRg==" >> > > The error is that you just revealed your credentials to the whole > world. This is a public mailing list. > > In fact, you just revealed your credentials to TWO mailing lists at once. I think the term 'script kiddie' applies here. > Good job. > > ChrisA -- Without followers, evil cannot spread. [Spock, "And The Children Shall Lead", stardate 5029.5] -- https://mail.python.org/mailman/listinfo/python-list
How to uninstall/update modules
Dear All, It seems I don't understand how Python packages are handled. Here's my specific problem * I'm on Win32 * I've installed Enthought Python 2.5 because it got all the numerical stuff included * Later I tried to install Twisted 8.1 Twisted ended up in C:\Python\Lib\site-packages\twisted But there's an older Twisted included in the Enthought distribution. It is at C:\Python\Lib\site-packages\Twisted-2.5.0.0002-py2.5-win32.egg Now, the strange thing (for the uninitiated, like me) is: When doing a "import twisted" I get to older version in directory Twisted-2.5.0.0002-py2.5-win32.egg, not the newer version in directory twisted. (A) What magic is going on in redirecting the import? (B) How can I switch to use the newer version? Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list
RegExp: "wontmatch"-function
Dear All, I'm looking for a function which, given a regexp re and and a string str, returns whether re won't match any string starting with str. (so it would always return False if str is "" or if str itself matches re -- but that are only the easy cases). I have the vague feeling that the internal workings of the regexp matcher can answer the question, but that there's no way to get this result from Python code. Any ideas or prior art on how to get this function? Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 - the hardest hello world ever ?
Hi Helmut, All, > do I miss something (I do hope so) or is switching to Python3 > really hard for Latin1-users? It's as complicated as ever -- if you have used unicode strings in the past (as the 3.0 strings now are always unicode strings). > # sys.setfilesystemencoding('latin1') This cares about the character encoding in filenames, not in file content. sys.setdefaultencoding('iso-8859-1') # or 'latin1' would do the job, but only in sitecustomize.py. After initializing, the function is no longer available. And using it in sitecustomize.py is sort of discouraged. IMHO the assumptions the typical Python installation makes about the character encoding used in the system are much too conservative. E.g. under Windows it should it use GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, ...). Then a lot of things would work out of the box. Of course including some methods to shoot yourself in the foot, which you are prevented from by the current behaviour. Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone Have (XP) 2.4.4 Installed and Can Check This Simple matplotlib Program?
On Oct 15, 6:38 am, "W. eWatson" <[EMAIL PROTECTED]> wrote: > I'm going to try another stab at this problem again. I'd like someone with > 2.4.4 and matplotlib-0.98.3.win32-py2.4exe to try it (below). IMHO an important detail of your configuration is missing. What's your numerical library? Did you install a Win32 distribution including a numerical library (which?), or which package do you have installed separately? In general I've used matplotlib with every Python version between 2.2 and 2.5 (inclusive) on Win32 without problem, but the separate installation was sometimes a problem. Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the instance reference of an object
Instead of comparing integers: > x = 1 > y = x # does assignment make copies? > y += 1 > assert x == 1 > => succeeds, which implies that Python makes a copy when assigning with lists: > x = [1] > y = x # does assignment make copies? > y += [1] > assert x == [1] > => fails, which implies that Python uses references when assigning Compare lists with tupels: x = (1,) y = x # does assignment make copies? y += (1,) assert x == (1,) => succeeds, which implies *what*? Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: encoding in lxml
Hi Mike, > I read an HTML document from a third-party site. It is supposed to be > in UTF-8, but unfortunately from time to time it's not. There will be host of more lightweight solutions, but you can opt to sanizite incominhg HTML with HTML Tidy (python binding available). It will replace invalid UTF-8 bytes with U+FFFD. It will not guess a better encoding to use. If you are sure you don't have HTML sloppiness to correct but only the occasional wrong byte, even decoding (with fallback) and encoding using the standard codec package will do. Regards, Peter -- http://mail.python.org/mailman/listinfo/python-list
hospedagem de sites - planos de hospedagem - hospedagem 41677
Tudo sobre hospedagem de sites , planos profissionais , economicos e muitos outros , sua empresa na internet por apenas 2,99 ao mês! http://www.hosting4u.com.br hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem hospedagem site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site site dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio dominio webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger webdesiger registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro registro website website website website website website website website website website website website website website website website website website website website website website website website website website website website website website profissional profissional profissional profissional profissional profissional profissional profissional desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver desenvolver hospedagem php hospedagens php hospedagens de sites hospedagens de páginas hospedagens de webpages hospedagens de homepages hospedagens mysql hospedagens sql hospedagens de site hospedagens baratas hospedagens profissionais hospedagem php hospedagem de sites hospedagem de site hospedagem de páginas hospedagem de webpages hospedagens de homepages hospedagem mysql hospedagem sql hospedagem de site hospedagem barata hospedagem profissional host hospedagem de site -- http://mail.python.org/mailman/listinfo/python-list
Please help with Threading
This is my first script where I want to use the python threading module. I have a large dataset which is a list of dict this can be as much as 200 dictionaries in the list. The final goal is a histogram for each dict 16 histograms on a page ( 4x4 ) - this already works. What I currently do is a create a nested list [ [ {} ], [ {} ] ] each inner list contains 16 dictionaries, thus each inner list is a single page of 16 histograms. Iterating over the outer-list and creating the graphs takes to long. So I would like multiple inner-list to be processes simultaneously and creating the graphs in "parallel". I am trying to use the python threading for this. I create 4 threads loop over the outer-list and send a inner-list to the thread. This seems to work if my nested lists only contains 2 elements - thus less elements than threads. Currently the scripts runs and then seems to get hung up. I monitor the resource on my mac and python starts off good using 80% and when the 4-thread is created the CPU usages drops to 0%. My thread creating is based on the following : http://www.tutorialspoint.com/python/python_multithreading.htm Any help would be create!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
I will post code - the entire scripts is 1000 lines of code - can I post the threading functions only? -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
Terry Jan Reedy wrote: >> Do you think tkinter is going to be the standard python built-in gui >> solution as long as python exists? > > AT the moment, there is nothing really comparable that is a realistic > candidate to replace tkinter. FLTK? (http://www.fltk.org/index.php) -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: serialize a class to XML and back
On 26-5-2013 22:48, Roy Smith wrote: > The advantage of pickle over json is that pickle can serialize many > types of objects that json can't. The other side of the coin is that > pickle is python-specific, so if you think you'll ever need to read your > data from other languages, pickle is right out. That is not entirely true :) I've written a pickle implementation for Java and .NET that is almost feature complete; it is part of http://pythonhosted.org/Pyro4/pyrolite.html Still, pickle may not be the best choice here. Cheers Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
Cameron Simpson wrote: > if s is not None and len(s) > 0: > ... do something with the non-empty string `s` ... > > In this example, None is a sentinel value for "no valid string" and > calling "len(s)" would raise an exception because None doesn't have > a length. obviously in this case an `if s: ...` is more than sufficient :P -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
Fábio Santos wrote: >> This should make life easier for us > http://docs.python.org/3/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy > > Speaking of PEPs and exceptions. When do we get localized exceptions? What do you mean by "localized exceptions"? Please, tell me it's *NOT* a proposal to send the exception message in the locale language! -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: serialize a class to XML and back
On 27-5-2013 2:39, Roy Smith wrote: > In article <51a28f42$0$15870$e4fe5...@news.xs4all.nl>, > Irmen de Jong wrote: > >> On 26-5-2013 22:48, Roy Smith wrote: >> >>> The advantage of pickle over json is that pickle can serialize many >>> types of objects that json can't. The other side of the coin is that >>> pickle is python-specific, so if you think you'll ever need to read your >>> data from other languages, pickle is right out. >> >> That is not entirely true :) I've written a pickle implementation for Java >> and .NET >> that is almost feature complete; it is part of >> http://pythonhosted.org/Pyro4/pyrolite.html > > Very cool > >> Still, pickle may not be the best choice here. > > Perhaps not, but lots of points for the awesomeness factor. > Thanks for the praise :) There's another interesting thing perhaps to also mention about Pyrolite. Its Pickle implementation obviously maps built in types to their counterparts in Java/.NET, but it is also capable of unpickling custom classes. It defaults to outputting a simple hashtable with the class's properties in it, but you can also provide a custom deserializer to recreate a custom object (it already does this automatically for a few complex types such as DateTime, BigDecimal, and a bunch of Pyro specific types). As the unpicklers are not executing any Java or .NET code dynamically they are not susceptible to the security issue that Python's pickle has. Still: tread with care. (Especially if you use the lib to pickle stuff and unpickle it on the Python side). Also, the one missing feature is memo-ing when pickling so that you can pickle recursive object graphs. It now throws a stack overflow exception instead. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
Fábio Santos wrote: >> > > Speaking of PEPs and exceptions. When do we get localized exceptions? >> > >> > What do you mean by "localized exceptions"? >> > >> > Please, tell me it's *NOT* a proposal to send the exception message in >> > the >> > locale language! >> It is. I think I read it mentioned in python-dev or this list. > > Here is what I read. > > http://mail.python.org/pipermail/python-dev/2013-April/125364.html > > It wasn't only about exceptions after all. And it seems like something > that will only happen far into the future. I really hope really far... have you never tried to google a localized error message? :\ -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help with Threading
On Saturday, 18 May 2013 10:58:13 UTC+2, Jurgens de Bruin wrote: > This is my first script where I want to use the python threading module. I > have a large dataset which is a list of dict this can be as much as 200 > dictionaries in the list. The final goal is a histogram for each dict 16 > histograms on a page ( 4x4 ) - this already works. > > What I currently do is a create a nested list [ [ {} ], [ {} ] ] each inner > list contains 16 dictionaries, thus each inner list is a single page of 16 > histograms. Iterating over the outer-list and creating the graphs takes to > long. So I would like multiple inner-list to be processes simultaneously and > creating the graphs in "parallel". > > I am trying to use the python threading for this. I create 4 threads loop > over the outer-list and send a inner-list to the thread. This seems to work > if my nested lists only contains 2 elements - thus less elements than > threads. Currently the scripts runs and then seems to get hung up. I monitor > the resource on my mac and python starts off good using 80% and when the > 4-thread is created the CPU usages drops to 0%. > > > > My thread creating is based on the following : > http://www.tutorialspoint.com/python/python_multithreading.htm > > > > Any help would be create!!! Thanks to all for the discussion/comments on threading, although I have not been commenting I have been following. I have learnt a lot and I am still reading up on everything mentioned. Thanks again Will see how I am going to solve my senario. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pillow lib for x86_64 GNU/Linux
On 3-6-2013 18:23, consult...@gmail.com wrote: > It is great that Pillow wants to be "setuptools compatible" but without a > suitable compiled library for x86_64 GNU/Linux, I am stuck between a rock and > a hard place. > > Any suggestions? > Try your distribution's package repository. $ sudo apt-get install python-pillow Or failing that, $ sudo apt-get install python-imaging Worked fine for me (Ubuntu 64-bit) Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: The problem with "print"
Rick Johnson wrote: > Take your > standard yes/no/cancel dialog, i would expect it to return > True|False|None respectively, you clearly mean True / False / FileNotFound. ( http://thedailywtf.com/Articles/What_Is_Truth_0x3f_.aspx ) -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
problem uploading docs to pypi
Hi, I'm experiencing some trouble when trying to upload the documentation for one of my projects on Pypi. I'm getting a Bad Gateway http error message. Anyone else experiencing this? Is this an intermittent issue or is there a problem with Pypi? Downloading documentation (from pythonhosted.org) works fine. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: problem uploading docs to pypi
On 15-6-2013 2:23, MRAB wrote: > About 10 ten days ago I got the error: > > Upload failed (503): backend write error > > while trying to upload to PyPI, and it failed the same way the second time, > but worked some > time later. You're right. I tried it again just now and it succeeded this time. Cheers Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Python to automatically boot my computer at a specific time and play a podcast
On 17-6-2013 15:24, inq1ltd wrote: > On Sunday, June 16, 2013 12:06:08 PM C. N. Desrosiers wrote: > >> Hi, > >> > >> I'm planning to buy a Macbook Air and I want to use it as a sort of alarm. >> I'd like to write a program that boots my computer at a specific time, >> loads iTunes, and starts playing a podcast. Is this sort of thing possible >> in Python? You can use the osascript utility to send commands to itunes, and invoke it from Python like this: import subprocess listname = "My Playlist" subprocess.call(["osascript", "-e", "tell application \"iTunes\" to play playlist \"{0}\"".format(listname)]) But that seems overkill (using Python to use Applescript to control iTunes)... Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a name for a deployment framework...
On 24-6-2013 20:13, Cousin Stanley wrote: > jonathan.slend...@gmail.com wrote: > >> Any suggestions for a good name, >> for a framework that does >> automatic server deployments ? > > asdf : automatic server deployment framework > > :-) wsad: wonderful serverside automatic deployments (hm, could use a bit of tweaking, maybe FPS keys don't map easily to names) Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: class factory question
On 27-6-2013 15:48, Dave Angel wrote: >> The behavior for these is all the same so they're subclassed >> from one base class, but they need to have these particular names so the >> parser knows >> how to consume them when encountered in the source file. That is, for every >> custom >> command the parser encounters, it looks for a class of that name in order to >> tokenize it. ^ How does it look for a class? Can you perhaps override the way it looks for a class of that name? So that you can instead return something sensible rather than having to define one of 50 almost identical classes... Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: math functions with non numeric args
On 30-6-2013 20:46, Andrew Z wrote: > Hello, > > print max(-10, 10) > 10 > print max('-10', 10) > -10 > > My guess max converts string to number bye decoding each of the characters to > it's ASCII > equivalent? > > Where can i read more on exactly how the situations like these are dealt with? > > Thank you > AZ > Use Python 3.x instead. >>> max('-10',10) Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() > str() >>> Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: socket data sending problem
On 4-7-2013 0:38, ollietemple...@aol.com wrote: > it all works fine, except for when i try to use: > > s.send("hello") > > to send data between the client and server, i just get this error message: > > >>> > Traceback (most recent call last): > File "C:/Users/Ollie/Documents/code/chatroom/client3.py", line 9, in > > s.send("hello") > TypeError: 'str' does not support the buffer interface > >>> Are you using Python 3.x? Try sending bytes instead of strings: s.send(b"hello") Or switch to using Python 2.7 Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check for threads being finished?
On 5-7-2013 18:59, Steven D'Aprano wrote: > I then block until the threads are all done: > > while any(t.isAlive() for t in threads): > pass > > > Is that the right way to wait for the threads to be done? Should I stick > a call to time.sleep() inside the while loop? If so, how long should I > sleep? That's probably an unanswerable question, but some guidelines on > choosing the sleep time will be appreciated. > I think your while loop busy-waits until the threads are completed. Do this instead: for t in threads: t.join()# optionally pass a timeout to join -Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Python - remote object protocols and security
On 15-7-2013 13:17, Dave Angel wrote: > On 07/15/2013 06:20 AM, Jean-Michel Pichavant wrote: >> In text format... sorry for my previous html post >> >> Hello everyone, >> >> I'd like to exchange some simple python objects over the internet. >> I initially planned to use Pyro, after reading >> http://pythonhosted.org/Pyro4/security.html I'm still puzzled. Hi, Pyro's author here. I agree that this chapter of the manual can use some cleanup. Is there anything in particular that you are puzzled about at this time? >> >> I don't mind encrypting data, if someone wants to sniff what I'm sending, >> he's welcome. >> I don't quite understand what you're saying in this sentence: is it okay if someone eavesdrops on your unencrypted data stream? >> What I think I need to care about, is malicious code injections. Because both >> client/server will be in python, would someone capable of executing code by >> changing >> one side python source ? Pyro since version 4.20 uses a serialization format that is safe against arbitrary code execution: https://pypi.python.org/pypi/serpent That format only encodes and decodes Python literal expressions, and no arbitrary objects are instantiated. You can also tell Pyro to use JSON (or marshal even), both of which should be impervious to this type of attack/vulnerability as well. The problem is with older Pyro versions, which allowed only Pickle to be used as serialization format. It is pickle that causes the remote code execution vulnerability. So as long as you don't explicitly tell Pyro (4.20+) to use pickle (a configuration switch), you should be safe. > I can't tell you if pyro, or any other particular one is safe. Pyro should be, since version 4.20 and provided you don't tell it to use pickle. See above. > Note that DOS attacks are possible whatever encoding scheme you have. Make > sure that > self-references within the data are well-defined (or impossible), and put > limits on size > per transaction, and transactions per minute per legitimate user. Pyro doesn't provide anything by itself to protect against this. Cheers Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: Python - remote object protocols and security
On 15-7-2013 18:57, Irmen de Jong wrote: >> Note that DOS attacks are possible whatever encoding scheme you have. Make >> sure that >> self-references within the data are well-defined (or impossible), and put >> limits on size >> per transaction, and transactions per minute per legitimate user. > > Pyro doesn't provide anything by itself to protect against this. I'm sorry to follow up on myself, but there is actually one thing: Pyro's choice of serializers (except pickle, again) don't allow self-references. So that type of DOS attack (infinite recursion) is ruled out. Irmen -- http://mail.python.org/mailman/listinfo/python-list
a little more explicative error message?
Hi I was writing a decorator and lost half an hour for a stupid bug in my code, but honestly the error the python interpreter returned to me doesn't helped... $ python3 Python 3.3.0 (default, Feb 24 2013, 09:34:27) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from functools import wraps >>> def dec(fun): ... @wraps ... def ret(*args, **kwargs): ... return fun(*args, **kwargs) ... return ret ... >>> @dec ... def fun(): pass ... >>> fun() Traceback (most recent call last): File "", line 1, in TypeError: update_wrapper() missing 1 required positional argument: 'wrapper' >>> $ Soo... at a first glance, no tricks... can you tell where is the error? :D As I said, the error is totally mine, I just forgot to pass the function as parameter to wraps. But... what is "update_wrapper()"? and "wrapper"? There is no useful traceback or something... just... this. Ok, the documentation clearly says: This is a convenience function to simplify applying partial() to update_wrapper(). So, again, shame on me... I just read carefully the doc *after* 20 minutes trying everything else... still... I think should be useful if wraps() intercept this error saying something more explicit about the missing fun parameter... -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it that easy to install Python ?
On 25-7-2013 17:11, santiago.d...@caoba.fr wrote: > Hi there, > > I never write any Python program but as a system administrator, I'm often > asked to install python on Debian servers. > > I just finished downloading, configuring, making and installing. > > The binary is now installed in : > /usr/local/Python-2.7.5/bin/python2.7 > (the path is a deliberate administrator choice). > > Is that it? > > What else will my users need? Why didn't you use the Debian package instead? You now have installed an unsupported, untested custom built Python version on your server. Why not simply $ apt-get install python and let the Debian package maintainers take care of properly testing and supporting it... Also, installing additional python packages will be much less of a hassle because there's hundreds of them readily available in Debian's package repositories and they can be installed (including correct dependencies) in the same way. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread is somehow interfering with a while loop called after the thread is started
On 28-7-2013 4:29, dan.h.mciner...@gmail.com wrote: > I have a simple scapy + nfqueue dns spoofing script that I want to turn into > a thread within a larger program: > > http://www.bpaste.net/show/HrlfvmUBDA3rjPQdLmdp/ > > Below is my attempt to thread the program above. Somehow, the only way the > while loop actually prints "running" is if the callback function is called > consistently. If the callback function isn't started, the script will never > print "running". How can that be if the while loop is AFTER the thread was > started? Shouldn't the while loop and the thread operate independantly? > > http://bpaste.net/show/0aCxSsSW7yHcQ7EBLctI/ > Try adding sys.stdout.flush() after your print statements, I think you're seeing a stdout buffering issue. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP8 79 char max
Ed Leafe wrote: > I had read about a developer who switched to using proportional fonts for > coding, and somewhat skeptically, tried it out. After a day or so it > stopped looking strange, and after a week it seemed so much easier to > read. By my (limited) experience with proportional fonts, they can be useful only with something like elastic tabstops[0]. But, as a general rule, I simply found more "squared" to just use a fixed-width font. [0] http://nickgravgaard.com/elastictabstops/ -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP8 79 char max
Joshua Landau wrote: >> By my (limited) experience with proportional fonts, they can be useful >> only with something like elastic tabstops[0]. But, as a general rule, I >> simply found more "squared" to just use a fixed-width font. > Not if you give up on the whole "aligning" thing. and this is one of the reason why I come back to fixed-width -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: splitting numpy array unevenly
On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote: > I need to divide a 512x512 image array with the first horizontal and vertical > division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit > want to start at the edges and create a bunch of same size arrays. Is there a > command to chop off different sized arrays? > > > > Thanks I don't know that I follow completely, but can't you just slice what you are after? x = np.random.rand(512*512).reshape(512,512) xx = x[0,:49] And put the rest of the slices in a loop...? -- http://mail.python.org/mailman/listinfo/python-list
Re: setup.py Choosing Older Compiler On Windows
On 2-12-2012 22:06, Dave Angel wrote: > On 12/02/2012 09:34 AM, Ami Tavory wrote: >> Hello, >> >> I'm porting a C++ extension module to a Windows machine that has both VC8 >> and VC10 installed. Unfortunately, `setup.py build` tries to build using >> VC8, which fails (the extension uses C++ standard libraries that VC didn't >> used to have). Is there a way to get setup.py to use VC10 (preferably >> externally, without modifying the script)? >> >> > > I haven't had to do Windows C++ development for many years, but there > used to be a vcvars.bat in each compiler installation, and you run the > one corresponding to the compiler & libraries you want. Forcing it to use a different compiler than the one that was used to build Python itself, may very well lead to a non-working extension module. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing packages on Mac OS X 10.7.5
On 6-12-2012 0:12, John Dildy wrote: > Hello Everyone! > > I have python v2.7.1 and I am trying to install packages on the Mac OS X > v10.7.5 > > I am trying to install: > > Distribute > > Nose > > virtualenv > > If anyone can help me that would be great > > John Dildy > > jdild...@gmail.com > Avoid changing stuff on the system installed python. If you don't have virtualenv already, I would suggest to either: - install virtualenv by means of easy_install (which should be installed already) - do everything else in a virtual env, instead of in the system installed python directly Or install homebrew, then brew install python, and use that. This avoids using the system installed python entirely. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: How to list a file which already created a 2 mins ago
On 6-12-2012 17:49, moonhkt wrote: > Hi All > > AIX.5.3 > Python 2.6.2 > > File ftp to Machine A, need to rename then send to Machine B. > > How to list a file which already created a 2 mins ago ? If file aging > more than 2 mins. I want to rename file to other file name. > > moonhkt > ftplib.FTP os.path.getmtime os.rename time.time Should be some pointers to get started. Irmen -- http://mail.python.org/mailman/listinfo/python-list
wrong ImportError message printed by python3.3 when it can't find a module?
Hi, I'm seeing that Python 3.3.0 is not printing the correct ImportError when it can't import a module that is imported from another module. Instead of printing the name of the module it can't import, it prints the name of the module that is doing the faulty import. Behold: I have created: importfail\ __init__.py main.py sub.py [L:\]type importfail\main.py from . import sub [L:\]type importfail\sub.py import nonexisting_module [L:\] [L:\]c:\Python33\python.exe -m importfail.main Traceback (most recent call last): File "C:\Python33\lib\runpy.py", line 160, in _run_module_as_main "__main__", fname, loader, pkg_name) File "C:\Python33\lib\runpy.py", line 73, in _run_code exec(code, run_globals) File ".\importfail\main.py", line 1, in from . import sub ImportError: cannot import name sub# <--- huh ? Python 3.2 and earlier do the right thing: [L:\]c:\Python32\python.exe -m importfail.main Traceback (most recent call last): File "C:\Python32\lib\runpy.py", line 160, in _run_module_as_main "__main__", fname, loader, pkg_name) File "C:\Python32\lib\runpy.py", line 73, in _run_code exec(code, run_globals) File "L:\importfail\main.py", line 1, in from . import sub File "importfail\sub.py", line 1, in import nonexisting_module ImportError: No module named nonexisting_module# <--- ok. (this is on windows, but on osx I see the same behavior). Is there a problem with the rewritten import logic in Python 3.3? Thanks Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: wrong ImportError message printed by python3.3 when it can't find a module?
On 7-12-2012 22:20, Peter Otten wrote: > A paragon of clarity -- ye lurkers, this is how a bug report should be. :-) > >> Is there a problem with the rewritten import logic in Python 3.3? >> >> Thanks >> Irmen de Jong > > I believe this is fixed, see http://bugs.python.org/issue15111 Argh, why didn't I search the bug tracker first: I would have found that one for sure. Anyway, thanks for pointing it out. The bug is confusing but it doesn't break anything so far. I guess I'll be fine waiting for 3.3.1. Irmen -- http://mail.python.org/mailman/listinfo/python-list
need some help with unexpected signal exception when using input from a thread (Pypy 1.9.0 on osx/linux)
Hi. Using Pypy 1.9.0. Importing readline. Using a background thread to get input() from stdin. It then crashes with: File "/usr/local/Cellar/pypy/1.9/lib_pypy/pyrepl/unix_console.py", line 400, in restore signal.signal(signal.SIGWINCH, self.old_sigwinch) ValueError: signal() must be called from the main thread Anyone seen this before? What's going on? When I don't import readline, or do the input() from within the main thread, the problem disappears. (I tried to reproduce it in a small test scenario but unfortunately have not been able to do so yet. Haven't figured out yet what the additional factors are that trigger this problem. A simple import readline and input() from a new thread doesn't seem to trigger it, unfortunately) Regards Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: Command Line Progress Bar
On 26-12-2012 7:17, Kevin Anthony wrote: > Hello, > I'm writing a file processing script(Linux), and i would like to have a > progress bar. > But i would also like to be able to print messages. Is there a simple way > of doing > this without implementing something like ncurses? This little library can prove useful: http://pypi.python.org/pypi/fish/ -Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting Unicode chars in Entry widget
On 29-12-2012 17:43, Alan Graham wrote: > Hello Python experts, > > I want to insert Unicode chars in an Entry widget by pushing on buttons; > one for each Unicode character I need. I have made the Unicode buttons. > I just need a simple function that will send the Unicode character to > the Entry widget. > Is there a better approach? > > Alan > Not sure what the question is. A better approach to doing what? I assuming you're doing tkinter (it is helpful if you mention the toolkit when posting a question). I'd create a function that you bind to all 'unicode buttons', and let the function insert the correct character depending on which button triggered it. A possible way to do that is to use a lambda with a different parameter for every button, like this: b1=Button(f, text='char1', command=lambda b=1: insert_char(b)) b2=Button(f, text='char2', command=lambda b=2: insert_char(b)) ...etc.. def insert_char(b): if b==1: entrywidget.insert(0, u"\u20ac") # inserts € in the entry widget e elif b==2: entrywidget.insert(0, ...some other char...) ... Or simply define a different command function for every button, then you don't have to use the lambda. -irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting Unicode chars in Entry widget
On 29-12-2012 18:23, Chris Angelico wrote: > On Sun, Dec 30, 2012 at 4:11 AM, Irmen de Jong wrote: >> b1=Button(f, text='char1', command=lambda b=1: insert_char(b)) >> b2=Button(f, text='char2', command=lambda b=2: insert_char(b)) >> ...etc.. >> >> def insert_char(b): >> if b==1: >> entrywidget.insert(0, u"\u20ac") # inserts € in the entry widget e >> elif b==2: >> entrywidget.insert(0, ...some other char...) >> ... > > I'm not familiar with tkinter syntax, but why not: > > b1=Button(f, text='char1', command=lambda: insert_char(1)) > b2=Button(f, text='char2', command=lambda: insert_char(2)) > > or even: > > b1=Button(f, text='char1', command=lambda: insert_char(u"\u20ac")) > b2=Button(f, text='char2', command=lambda: insert_char("... some other > char...")) > > Seems weird to multiplex like that, but if there's a good reason for > it, sure. I'm more of a GTK person than tkinter, and more of a > command-line guy than either of the above. > > ChrisA > You're right there's nothing special about tkinter there, I was copying some existing code a bit too literally. Simplify the lambdas as needed. :) Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner: Trying to get REAL NUMBERS from %d command
On 30-12-2012 23:37, Alvaro Lacerda wrote: > > I'm trying to get full number result using the %d command Try %f instead. %d is the formatting symbol for integer numbers. See http://docs.python.org/2/library/stdtypes.html#string-formatting-operations Or have a look at what string.format() can do: http://docs.python.org/2/library/string.html#format-examples -irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: test failed: test_urlwithfrag
On 7-1-2013 19:26, Elli Lola wrote: > I never used python before and installed it today the first time, so I have > no idea what > to do about this failure: > > > $ ./python -m test -v test_urlwithfrag [..snip..] > ImportError: No module named 'test.test_urlwithfrag' > > 1 test failed: > test_urlwithfrag The error message says it all, really: there is no regression test module called "test_urlwithfrag". (At least, not on my python 3.3 installation) Check the contents of your /Lib/test directory to see what is available instead. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Safely add a key to a dict only if it does not already exist?
Steven D'Aprano wrote: > I wish to add a key to a dict only if it doesn't already exist, but do it > in a thread-safe manner. > > The naive code is: > > if key not in dict: > dict[key] = value > > > but of course there is a race condition there: it is possible that > another thread may have added the same key between the check and the > store. > > How can I add a key in a thread-safe manner? using locks? import threading lock = threading.Lock() with lock: if key not in dict: dict[key] = value -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Safely add a key to a dict only if it does not already exist?
Chris Rebert wrote: >> How can I add a key in a thread-safe manner? > I'm not entirely sure, but have you investigated dict.setdefault() ? but how setdefault makes sense in this context? It's used to set a default value when you try to retrieve an element from the dict, not when you try to set a new one ... -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Safely add a key to a dict only if it does not already exist?
Peter Otten wrote: How can I add a key in a thread-safe manner? >>> I'm not entirely sure, but have you investigated dict.setdefault() ? >> >> but how setdefault makes sense in this context? It's used to set a >> default value when you try to retrieve an element from the dict, not when >> you try to set a new one ... > > But it also sets the value if the key is not found: yeah, sure, but with a fixed value :) I mean: if the value is not important, why bother at all trying not to override it with an if or a lock or other tecniques? doing d['key'] = 'fixed_value' multiple times in different threads is not a problem in my eyes... -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Safely add a key to a dict only if it does not already exist?
Peter Otten wrote: uhhmm.. I think I misread the example d = {} d.setdefault(1, 2) > 2 d > {1: 2} d.setdefault(1, 3) > 2 d > {1: 2} yeah, sure it can be useful for the OP... -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Thorough Python 2.7.3 Windows Build Documentation?
On 21-1-2013 18:16, Stephane Wirtel wrote: > Hi Leonard, > > Please, could you limit your text to 80 columns, because it's > unreadable. Your text is too long :( Stephane, shouldn't your news reader simply wrap the lines...? At least mine does. (Thunderbird) Irmen -- http://mail.python.org/mailman/listinfo/python-list
serpent, a serializer based around ast.literal_eval
Hi, I've been toying a bit with ast.literal_eval. I've come up with "serpent", a serializer based around that. Which means that it takes a Python object tree and turns it into a serialized form that can be safely read back by ast.literal_eval(). Why I wrote serpent and didn't simply use repr()+ast.literal_eval: * it serializes directly to bytes (utf-8 encoded), instead of a string, so it can immediately be saved to a file or sent over a socket * it encodes byte-types as base-64 instead of inefficient escaping notation that repr would use (this does mean you have to base-64 decode these strings manually on the receiving side to get your bytes back) * it contains a few custom serializers for several additional Python types such as uuid, datetime, array and decimal * it tries to serialize unrecognised types as a dict (you can control this with __getstate__ on your own types) * it can create a pretty-printed (indented) output for readability purposes * it works around a few quirks of ast.literal_eval() on the various Python implementations. It works with Python 2.6+ (including 3.x), IronPython 2.7+, Jython 2.7+. Serpent can be downloaded from Pypi: http://pypi.python.org/pypi/serpent A simple example session can be seen here: https://gist.github.com/4588429 I'm considering writing Java and .NET counterparts for this as well so I'll be able to exchange messages between the three. What do you think? Would you consider this useful at all? Cheers Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: Increase value in hash table
moonhkt wrote: > Data file > V1 > V2 > V3 > V4 > V4 > V3 > > How to using count number of data ? > > Output > V1 = 1 > V2 = 1 > V3 =2 > V4 = 2 import collections with open(data_file) as f: print(collections.Counter(f.readlines())) it's a start -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
MRAB wrote: > It turns out that both S & {x} and {x} & S return {x}, not {y}. curious. $ python Python 2.7.3 (default, Jul 3 2012, 19:58:39) [GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = (1,2,3) >>> y = (1,2,3) >>> s = set([y]) >>> (s & set([x])).pop() is y False >>> (set([x]) & s).pop() is y True maybe it's implementation-defined? -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing offset-aware and offset-naive datetimes?
Roy Smith wrote: > I have two datetimes. One is offset-naive. The other is offset-aware, > but I happen to know its offset is 0 (i.e. GMT). How can I compare > these? http://pytz.sourceforge.net/#localized-times-and-date-arithmetic -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding MIME type for a data stream
On 8-3-2012 23:34, Tobiah wrote: > Also, I realize that I could write the data to a file > and then use one of the modules that want a file path. > I would prefer not to do that. > > Thanks > Use StringIO then, instead of a file on disk Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Raise X or Raise X()?
On 11-3-2012 20:04, bvdp wrote: > Which is preferred in a raise: X or X()? I've seen both. In my specific case > I'm dumping out of a deep loop: > > try: > for ... > for ... > for ... > if match: >raise StopInteration() > else ... > > except StopInteration: >print "found it" "raise X" is a special case of the 3-args raise. Effectively it just raises an instance of X which is constructed with an empty argument list. Therefore, "raise X()" is equivalent, as far as I know. See http://docs.python.org/reference/simple_stmts.html#the-raise-statement Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Will MySQL ever be supported for Python 3.x?
On 30-3-2012 23:20, John Nagle wrote: > The MySQLdb entry on SourceForge > (http://sourceforge.net/projects/mysql-python/) > web site still says the last supported version of Python is 2.6. > PyPi says the last supported version is Python 2.5. The > last download is from 2007. > > I realize there are unsupported fourth-party versions from other > sources. (http://www.lfd.uci.edu/~gohlke/pythonlibs/) But those > are just blind builds; they haven't been debugged. > > MySQL Connector (http://forge.mysql.com/projects/project.php?id=302) > is still pre-alpha. Try Oursql instead http://packages.python.org/oursql/ "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Will MySQL ever be supported for Python 3.x?
On 30-3-2012 23:46, John Nagle wrote: > On 3/30/2012 2:32 PM, Irmen de Jong wrote: >> Try Oursql instead http://packages.python.org/oursql/ >> "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" > >Not even close to being compatible with existing code. Every SQL > statement has to be rewritten, with the parameters expressed > differently. It's a good approach, but very incompatible. You didn't state that it had to be compatible with existing code. Also, since you asked about Python 3.x, surely there are other incompatibilities you need to take care of in the existing code? (unless it's Python 3.x clean already...) Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python 2.5.2 on Win 7
On 1-4-2012 22:11, W. eWatson wrote: > To solve this problem I thought I would install the software on my laptop > Win7 PC. When > I tried PIL.1.1.6 I got several unexpected messages that seem to indicate > things were > not going well. I have stopped to find out if it is really possible to > install this > suite of software on Win7. Is it possible? If not, will uninstalling Python > also remove > PIL? I'm using PIL 1.1.7 (the latest version available from effbot's website) on Windows 7. Admittedly, with Python 2.7.2, but there's an installer for Python 2.5 as well. I assume it should work just fine. What errors were you seeing? And no, uninstall Python won't remove PIL - it has its own uninstaller. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: ast.parse
On 9-4-2012 13:53, Kiuhnm wrote: > Is it a known fact that ast.parse doesn't handle line continuations and some > multi-line > expressions? > For instance, he doesn't like > for (x, > y) in each([1, > 2]): > print(1) > at all. > Is there a workaround besides "repairing" the code on the fly? > > Kiuhnm What Python version are you using and what is the exact error? It works fine here (Python 2.7.2): >>> import ast >>> code="""for (x, ... y) in each([1, ... 2]): ... print(1)""" >>> ast.parse(code) <_ast.Module object at 0x02418A10> Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggest design to accomodate non-unix platforms ?
On 18-4-2012 15:35, Richard Shea wrote: > ... which I think would work and be sufficiently flexible to deal with > alternatives to putty.exe but is there a more established (... > better !) way of doing this stuff ? Perhaps install Cygwin and use its ssh.exe? Or use the paramiko library? (which, I believe, implements SSH directly) Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Create directories and modify files with Python
On 1-5-2012 1:24, deltaquat...@gmail.com wrote: > Hi, 0 I would like to automate some simple tasks I'm doing by hand. Given a > text file > foobar.fo: [...] > At first, I tried to write a bash script to do this. However, when and if the > script > will work, I'll probably want to add more features to automate some other > tasks. So I > thought about using some other language, to have a more flexible and > mantainable > code. I've been told that both Python and perl are well suited for such > tasks, but > unfortunately I know neither of them. Can you show me how to write the script > in > Python? Thanks, Err.. if you don't know Python, why do you think a Python script will be more flexible and maintainable for you? But if you really want to go this way (and hey, why not) then first you'll have to learn some basic Python. A good resource for this might be: http://learnpythonthehardway.org/ Focus on file input and output, string manipulation, and look in the os module for stuff to help scanning directories (such as os.walk). Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Create directories and modify files with Python
On 1-5-2012 12:51, deltaquat...@gmail.com wrote: But if you really want to go this way (and hey, why not) then first you'll have to learn some basic Python. A good resource for this might be: http://learnpythonthehardway.org/ Ehm...name's not exactly inspiring for a newbie who's short on time :) It's just a name. That resource is generally regarded as one of the better books to learn Python for total beginners. If you can program already in another language, the standard Python tutorial might be more efficient to start from: http://docs.python.org/tutorial/ Thanks for the directions. By the way, can you see my post in Google Groups? I'm not able to, and I don't know why. I don't use Google groups. I much prefer a proper news agent to read my usenet newsgroups. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: How to compute a delta: the difference between lists of strings
J. Mwebaze wrote: > This is out of curiosity, i know this can be done with python diffllib > module, but been figuring out how to compute the delta, Consider two lists > below. > > s1 = ['e', 'f', 'g', 'A', 'B', 'C', 'D', 'C'] > s2 =['e', 'A', 'B', 'f', 'g', 'C', 'D', 'z'] > > This is the result should be > > [' e', '+ A', '+ B', ' f', ' g', '- A', '- B', ' C', ' D', '- C', '+ > z'] > > ideas on how to approach this.. ? http://en.wikipedia.org/wiki/Longest_common_subsequence_problem -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: .py to .pyc
On 13-5-2012 23:27, Colin J. Williams wrote: > Is there some way to ensure that a .pyc file is produced when executing a .py > file? > > It seems that for small files the .pyc file is not produced. > > Colin W. All modules no matter how small produce a .pyc file *when they are imported*. If you start a module directly though, no .pyc is produced. (Notice that Python 3 puts the pyc files in a subdirectory.) Why do you care anyway? Pyc files are an implementation detail. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI toolkits and dynamic table browser widget
Simon Cropper wrote: >>> I would like to create windows with grids (AKA rows and column of a >>> table like excel). Do any of the GUI interfaces have these types of >>> widgets? i have looked but can't find any and I have not stumbled on >>> program that presents data in this way so I can see how they do it. >>> >>> Specifically I would like to run a SQL command and have the returned >>> list passed to a widget with little or no manipulation and that widget >>> present the data, allow the user to scroll through that data and >>> preferably allow edits to occur. These edits could then be passed back >>> via a string to the program for inclusion in a sql-update command. >> Have a look at PyQt [1], specially QTableView [2] and QtSql [3] > That looks very promising... do you understand the licensing though? > > GPL to GPL is obvious but would development of an in-house system be > commercial or GPL licensing? If you're so scared of GPL, you should look at pyside: http://www.pyside.org/docs/pyside/PySide/QtGui/QTableView.html -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: installing 2 and 3 alongside on MS Windows
On 25-5-2012 10:24, Ulrich Eckhardt wrote: > Hi! > What I'm considering is installing Python 3 alongside, in order to > prepare the code for this newer version. What I'd like to know first is > whether there are any problems I'm likely to encounter and possible > workarounds. What I'm doing myself on Windows is deciding which version of Python I want to be the default, and install that from the msi normally (including "register extensions" options). I then proceed to add its install location to my %PATH%. After which I install additional Python versions but *without* selecting "register extensions" otherwise they will overwrite the registry associations. I have about 5 different versions coexisting peacefully in c:\python26 c:\python27 c:\python27-64, c:\python32 and c:\python33 (with python27 being the default and only c:\python27 added to %PATH%) In the IDE I'm using (PyCharm) you can trivially switch the Python version it will use for your project. > Thank you! > > Uli > > PS: Dear lazyweb, is there any way to teach VC8 some syntax highlighting > for Python? http://pytools.codeplex.com/ perhaps? Irmen. -- http://mail.python.org/mailman/listinfo/python-list
Re: Install lxml package on Windows 7
On 29-5-2012 22:41, David Fanning wrote: > Folks, > > I need some help. I need the lxml package to run a particular > Python program. > >http://lxml.de/ > > I downloaded the appropriate binary egg package for lxml, and > I found easy_install.exe in my Python 2.7 distribution. I ran > that. > > Then, at the command prompt I typed this: > >easy_install --allow-hosts=lxml.de,*.python.org lxml==2.3.4 [..snip..] Save yourself the pain trying to get it to build from source. Instead, just install a precompiled binary, for instance the one available from: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml -Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: ./configure
On 4-6-2012 0:01, Janet Heath wrote: > > Thanks Alain. I should have a compiler on my Mac OS X Lion. I am thinking > that it > isn't set in my $PATH variable. I don't know where the $PATH is set at. I > will > check to see if their is a binary. You'll have to have the Apple Developer tools (xcode) installed to get a c-compiler, but maybe that's the case on your mac already. (Weird though, it should add gcc -the compiler- to the PATH by itself, I don't recall having to change that myself.) In any case, there is a .dmg with a binary installer for Python 2.7.3 available for download at python.org [1] so there should not really be a need to compile it yourself. If you really do need to compile it yourself, consider using Homebrew [2] to install it, instead of downloading the source and compiling it manually. With homebrew it's a simple 'brew install python' and a few minutes later it's done. It will be lot easier to install 3rd party library dependencies this way too. Irmen. [1] http://python.org/download/releases/2.7.3/ [2] http://mxcl.github.com/homebrew/ -- http://mail.python.org/mailman/listinfo/python-list
PIL for the Python 3.2.3
Dear Python Org, It wanted to know if already PIL's version is available for Python 3.2.3. Thanks. Gonzalo -- http://mail.python.org/mailman/listinfo/python-list
Re: Function call arguments in stack trace?
On 7-6-2011 21:31, Dun Peal wrote: > On Jun 7, 1:23 pm, Neil Cerutti wrote: >> Use pdb. > > Neil, thanks for the tip; `pdb` is indeed a great debugging tool. > > Still, it doesn't obviate the need for arguments in the stack trace. If you can't use pdb perhaps you can use the following: Pyro has always had a feature that prints detailed stacktraces. It is mainly meant to clarify stacktraces that occur on a different machine (where you don't have the option of using pdb), but can very well be used for normal code too: import sys import Pyro4.util Pyro4.config.DETAILED_TRACEBACK=True sys.excepthook=Pyro4.util.excepthook def divide(a,b): return a//b def dividebysomething(a): return divide(a,0) print dividebysomething(10) When you run this, this will be printed: [E:\projects]python trace.py -- <> RAISED : integer division or modulo by zero Extended stacktrace follows (most recent call last) -- File "trace.py", line (13), in Source code: print dividebysomething(10) File "trace.py", line (11), in dividebysomething Source code: return divide(a,0) Local values: a = 10 -- File "trace.py", line (8), in divide Source code: return a//b Local values: a = 10 b = 0 -- <> RAISED : integer division or modulo by zero -- You can find the relevant code that produces these kinds of tracebacks in the util.py source file of Pyro. You can get that from Pypi: http://pypi.python.org/pypi/Pyro4/ or the file directly from subversion: $ svn export svn://svn.razorvine.net/Pyro/Pyro4/trunk/src/Pyro4/util.py Perhaps you can use this or adapt it to suit your needs. Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: To install lxml (and easy_install) for Python 3 under Windows...
On 12-6-2011 18:38, ncdave4l...@mailinator.com wrote: > I had difficulty installing lxml for Python 3.1 under Windows, and > took some notes as I worked through it. Here's how I finally managed > it... > > [...] In cases like this, Christoph Gohlke's page with 'Unofficial Windows Binaries for Python Extension Packages' can be very handy: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml -irmen -- http://mail.python.org/mailman/listinfo/python-list
Infinite recursion in __reduce__ when calling original base class reduce, why?
Hi, I'm having a rather obscure problem with my custom __reduce__ function. I can't use __getstate__ to customize the pickling of my class because I want to change the actual type that is put into the pickle stream. So I started experimenting with __reduce__, but am running into some trouble. I've pasted my test code below. It works fine if 'substitute' is True, but as soon as it is set to False, it is supposed to call the original __reduce__ method of the base class. However, that seems to crash because of infinite recursion on Jython and IronPython and I don't know why. It works fine in CPython and Pypy. I wonder if my understanding of __reduce__ is wrong, or that I've hit a bug in IronPython and Jython? Do I need to do something with __reduce_ex__ as well? Any help is very much appreciated. Irmen de Jong # ironpython / jython __reduce__ recursion problem test program import pickle class Substitute(object): def __init__(self, name): self.name=name def getname(self): return self.name class TestClass(object): def __init__(self, name): self.name=name self.substitute=True def getname(self): return self.name def __reduce__(self): if self.substitute: return Substitute, ("SUBSTITUTED:"+self.name,) else: # call the original __reduce__ from the base class return super(TestClass, self).__reduce__() # crashes on ironpython/jython obj=TestClass("janet") s=pickle.dumps(obj) d=pickle.loads(s) print(d) print(d.getname()) # now disable the substitution and try again obj.substitute=False s=pickle.dumps(obj) d=pickle.loads(s) print(d) print(d.getname()) -- http://mail.python.org/mailman/listinfo/python-list
Re: working with raw image files
what is a .raw file, do you mean a flat binary? -- http://mail.python.org/mailman/listinfo/python-list
Re: Infinite recursion in __reduce__ when calling original base class reduce, why?
On 14-6-2011 2:40, Chris Torek wrote: > > Nonetheless, there is something at least slightly suspicious here: [... snip explanations...] Many thanks Chris, for the extensive reply. There's some useful knowledge in it. My idea to call the base class reduce as the default fallback causes the problems: return return super(TestClass, self).__reduce__() If, following your suggestion, I replace that with: return self.__class__, (self.name,) it works fine. By the way, in the meantime I've played around with copyreg.pickle, and that code worked in all Python implementations I've tried it in. This code feels better too, because it is possible to simply use return self.__reduce__() as a fallback in it, because we're not touching the object's own __reduce__ in any way. Anyway thanks again Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: debugging https connections with urllib2?
On 18-6-2011 20:57, Roy Smith wrote: > We've got a REST call that we're making to a service provider over https > using urllib2.urlopen(). Is there any way to see exactly what's getting > sent and received over the network (i.e. all the HTTP headers) in plain > text? Things like tcpdump and strace only have access to the encrypted > data. > > We can't just switch to using http because the endpoint we're talking to > (and don't have control over) refuses plain-text connections. Put a proxy between the https-service endpoint and your client app. Let the proxy talk https and let your client talk http to the proxy. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
SherjilOzair wrote: > There are basically two ways to go about this. [...] > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? a third way maybe using a SkipList instead of a list on http://infohost.nmt.edu/tcc/help/lang/python/examples/pyskip/ you can find a pure python implementation (but afaik there are many others) -- ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed up a script that iterates over a large range (600 billion)?
On 21-06-11 21:48, John Salerno wrote: I'm working on the Project Euler exercises and I'm stumped on problem 3: "What is the largest prime factor of the number 600851475143 ?" Now, I've actually written functions to get a list of the factors of any given number, and then another function to get the prime numbers from that list. It works fine with small numbers, but when I try to feed my get_factors function with the above number (600 billion), naturally it takes forever! You need a better algorithm to calculate primes, and iterate over primes instead of over the full (half, or even better, sqrt(n)) range of possible values. You also should optimize the stop condition, once you find that the number can no longer be divided by larger primes you can stop the loop. For instance to get the prime factors of the number 1000 you'd iterate over the prime numbers 2,3,5 and conclude that 1000=2*2*2*5*5*5, so 5 would be the largest prime factor. No need to try larger primes than 5, let alone go through 1..sqrt(1000). The Sieve of Eratosthenes is a well known algorithm to calculate primes with reasonable efficiency. Irmen -- http://mail.python.org/mailman/listinfo/python-list