Re: Changing the EAX register with Python
Hi, just read my mail :-) You can just build an debugger in python yourself. The script I posted should give you an idea. Am Fr, 19.11.2010, 08:17 schrieb Tim Roberts: > dutche wrote: >> >>Hi folks, I have a unusual question here. >> >>How can I change the value of EAX register under python under Linux?? >>As paimei does under Windows. >> >>My project is to have a python program that loads a C program and sets >>a breakpoint at some address, and then with this breakpoint I change >>the EAX register and then continue the program execution. >> >>With Windows and paimei I did that, but under Linux I don't know yet. > > You will need to find a Linux application equivalent to PaiMei. Your > question is not "how can I change EAX", your question is "where can I find > a Linux debugger that can be controlled from Python?" > > I don't know the answer to that. gdb is quite powerful, and you can > certainly control it by connecting to its stdin and stdout connections. > -- > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > -- > http://mail.python.org/mailman/listinfo/python-list > > -- MfG, Stefan Sonnenberg-Carstens IT Architect -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution of Python Scripts
tazz_ben wrote: Hi Folks - I'm an experienced programmer, but this is my first app with python, so I apologize for any stupidity on my part. So I've written/still working on a command line tool written in Python. It talks to a web service, so there really isn't anything in it that is dependent on a particular os. My goal is to distribute the script as a tool to my users so they can use it (they are on multiple platforms), the vast majority are not programmers. So, I'm looking for a way to distribute the app that takes care of details like them having python installed, or having an older version etc. From reading some docs it sounds like "Squeeze" did exactly this back in the day, but it is ancient and I'm writing in 2.7. Just to be clear I could care less if they see the source code, my goal is all around ease of use. I would love to have one distribution file for all platforms, but I can live with making three if that's the only option. So, what's my options. I've never done that before. So maybe I will give you a very bad idea, but if so, I'm confident that ppl in this list will scream about it :) You can ship your app with python (the executable) and the module you're using as local modules. Let's assume you are importing sys and os: myApp/python.exe myApp/myScript.py myApp/os/__init__.py -> actually the whole package myApp/sys/__init__.py If you see what I mean. by running python.exe myScript.py ... That should work. You'll have to include every single module you are using. Only python.exe would required to be platform specific. Maybe that's a terrible thing to do... :D JM -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
Hello, On Tue, Nov 16, 2010 at 01:52:42PM -0800, Ian wrote: > The proper way to get the number of rows is to > use the COUNT aggregate function, e.g., "SELECT > COUNT(*) FROM TABLE1", which will return a > single row with a single column containing the > number of rows in table1. It's better to select count(1) instead of count(*). The latter may skip rows consisting entirely of NULLs IIRC. -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
HI ALL, COUPLE R INVITING U FOR HOT DATING FOR FREE.... PLZ WELCOME(ABOVE 18YEARS ONLY)
HI ALL, COUPLE R INVITING U FOR HOT DATING FOR FREE PLZ WELCOME(ABOVE 18YEARS ONLY) http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 http://x2c.eu/58 -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
On Fri, Nov 19, 2010 at 01:14:34PM +0200, Alexander Gattin wrote: > On Tue, Nov 16, 2010 at 01:52:42PM -0800, Ian > wrote: > > The proper way to get the number of rows is to > > use the COUNT aggregate function, e.g., "SELECT > > COUNT(*) FROM TABLE1", which will return a > > single row with a single column containing the > > number of rows in table1. > > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. sorry, I'm wrong -- count(*) behaves the same way as count(1) does: sqlite> create table t (x number, y char); sqlite> insert into t(x,y) values(1,'a'); sqlite> insert into t(x,y) values(2,NULL); sqlite> insert into t(x,y) values(NULL,'c'); sqlite> insert into t(x,y) values(NULL,NULL); sqlite> insert into t(x,y) values(NULL,NULL); sqlite> select count(1),count(*),count(x),count(y) from t; 5|5|2|2 sqlite> P.S. Surprise -- it's true even for Oracle SQL... -- With best regards, xrgtn (+380501102966/+380636177128/xr...@jabber.kiev.ua) -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
Alexander Gattin writes: >> The proper way to get the number of rows is to >> use the COUNT aggregate function, e.g., "SELECT >> COUNT(*) FROM TABLE1", which will return a >> single row with a single column containing the >> number of rows in table1. > > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. Wrong: count(anyname) ignores NULL, whereas count(*) does not. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: strange subprocess behavior when calling ps
Hello, On Wed, Nov 17, 2010 at 01:19:09AM -0800, Ned Deily wrote: > As far as I know, COMMAND_MODE has no special > meaning on other platforms UNIX_STD=2003 on HP-UX if anyone's interested... -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
On Freitag 19 November 2010, Alexander Gattin wrote: > It's better to select count(1) instead of > count(*). The latter may skip rows consisting > entirely of NULLs IIRC. in some data bases count(1) is said to be faster than count(*), I believe -- Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
Hello, On Fri, Nov 19, 2010 at 12:32:19PM +0100, Alain Ketterlin wrote: > Alexander Gattin writes: > > It's better to select count(1) instead of > > count(*). The latter may skip rows consisting > > entirely of NULLs IIRC. > > Wrong: count(anyname) ignores NULL, whereas count(*) does not. I'm using count(1), which is a count over constant non-NULL expression (1). It doesn't ignore NULLs or duplicate rows, as my attempts with Oracle 10g, 8g and sqlite3 show. -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
Alexander Gattin writes: > On Fri, Nov 19, 2010 at 12:32:19PM +0100, Alain > Ketterlin wrote: >> Alexander Gattin writes: >> > It's better to select count(1) instead of >> > count(*). The latter may skip rows consisting >> > entirely of NULLs IIRC. >> >> Wrong: count(anyname) ignores NULL, whereas count(*) does not. > > I'm using count(1), which is a count over constant > non-NULL expression (1). It doesn't ignore NULLs > or duplicate rows, as my attempts with Oracle 10g, > 8g and sqlite3 show. I'm not saying anything about count(1) (which works like count(*) as you explain, even though I see no point in using 1, since *'s hehavior is well-defined). What was wrong in your first message is that count(*) ignores NULL (granted, you've corrected your mistake in a later message, which I didn't see before posting). -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extension on Windows
Eric Frederich wrote: > I am trying to create an extension on Windows and I may be over my > head but I have made it pretty far. > > I am trying to create bindings for some libraries which require me to > use Visual Studio 2005. > > I set up the spammodule example and in VS set the output file to be a .pyd > file. When I copy that .pyd file into site-packages I can use it just fine > and call system('dir'). A ".pyd" is a ".dll", just with a different extension. That means that you can use all tools for DLLs on those, too, like e.g. dependencywalker[1] in order to check for missing dependent DLLs. If the name of the PYD is "foo.pyd", Python looks for a function "foo_init" (or "init_foo") which it calls in order to register the contained code. If this is missing or has the wrong name, Python won't load it. That means that you can't rename the file without touching its content! > Now when I created a 2nd function to wrap a library function I get the > following. > > ImportError: DLL load failed: The specified module could not be found. This can mean that the module itself couldn't be loaded or that one of the DLLs it depends on couldn't be found. Use dependencywalker to check. > I added the correct additional include directories and specified the > correct .lib file to get it to compile fine without any errors. That may be so, but it won't make the system pick up the DLL from whichever location you installed it to. > What is going on here? I tried running python with -vvv and got no > meaningful info... it just fails. Python tries to load the DLL and only gets told by the system that "the DLL failed to load", but not which one. I'm afraid Python can't do any better, since it doesn't have any better info itself. Uli [1] http://dependencywalker.com -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to correctly pass “pointer-to-pointer ” into DLL via ctypes?
Grigory Petrov writes: > Hello. > > I have a DLL that allocates memory and returns it. Function in DLL is like > this: > > void Foo( unsigned char** ppMem, int* pSize ) > { > * pSize = 4; > * ppMem = malloc( * pSize ); > for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; > } > > Also, i have a python code that access this function from my DLL: > > from ctypes import * > Foo = windll.mydll.Foo > Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] > mem = POINTER( c_ubyte )() > size = c_int( 0 ) > Foo( byref( mem ), byref( size ) ] > print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] > > I'm expecting that print will show "4 0 1 2 3" but it shows "4 221 221 > 221 221" O_O. Any hints what i'm doing wrong? After correcting quite a few obvious errors in your code, it worked just fine for me. So I guess what you think you test is not what you test. --- test.py from ctypes import * foo = cdll.LoadLibrary("/Users/deets/projects/GH28/kinect/kinect/c/foo/libtest.dylib").foo foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] mem = POINTER( c_ubyte )() size = c_int( 0 ) foo( byref( mem ), byref( size ) ) print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] --- --- test.c void foo( unsigned char** ppMem, int* pSize ) { int i; * pSize = 4; * ppMem = malloc( * pSize ); for( i = 0; i < * pSize; i ++ ) (* ppMem)[ i ] = i; } --- --- CMakeLists.txt cmake_minimum_required (VERSION 2.6) project (Test) add_library(test SHARED test.c) --- -- Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
Hello, On Fri, Nov 19, 2010 at 01:03:14PM +0100, Wolfgang Rohdewald wrote: > On Freitag 19 November 2010, Alexander Gattin wrote: > > It's better to select count(1) instead of > > count(*). not true, > > The latter may skip rows consisting > > entirely of NULLs IIRC. not true either. I've heard that count(1) is preferred to count(*) but forgot why. Your post reveals the truth about my belief: > in some data bases count(1) is said to be faster > than count(*), I believe And as it turns out this isn't true anymore on modern databases (count(1) and count(*) behave exactly the same). And quite surprisingly, on old ones count(*) was faster than count(1): > 'Oracle Performance Tuning', second edition, > O'Reilly & Associates, Inc, page 175. It says: > > "Contrary to popular belief COUNT(*) is faster > than COUNT(1). If the rows are returned via an > index, counting the indexed column - for example, > COUNT(EMP_NO) is faster still. The optimizer > realizes from the existence of the index that the > column must also exist (non-null). We tested the > following statements on several different > computers and found that COUNT(*) consistently > runs between 15% and 20% faster than COUNT(1) and > that COUNT(INDEXED_COLUMN) is 5% faster again." // http://asktom.oracle.com/pls/asktom/f?p=100:11:0P11_QUESTION_ID:1156151916789 P.S. sorry for starting this discussion. -- With best regards, xrgtn -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the EAX register with Python
On Fri, Nov 19, 2010 at 4:17 PM, Tim Roberts wrote: > dutche wrote: >> >>Hi folks, I have a unusual question here. >> >>How can I change the value of EAX register under python under Linux?? >>As paimei does under Windows. >> >>My project is to have a python program that loads a C program and sets >>a breakpoint at some address, and then with this breakpoint I change >>the EAX register and then continue the program execution. >> >>With Windows and paimei I did that, but under Linux I don't know yet. > > You will need to find a Linux application equivalent to PaiMei. Your > question is not "how can I change EAX", your question is "where can I find > a Linux debugger that can be controlled from Python?" Well, gdb may just be the tool you are looking for: since version 7.0 at least, you can script gdb using python, http://sourceware.org/gdb/wiki/PythonGdb cheers, David -- http://mail.python.org/mailman/listinfo/python-list
Re: Extension on Windows
On Fri, Nov 19, 2010 at 7:28 AM, Ulrich Eckhardt wrote: >> Now when I created a 2nd function to wrap a library function I get the >> following. >> >> ImportError: DLL load failed: The specified module could not be found. > > This can mean that the module itself couldn't be loaded or that one of the > DLLs it depends on couldn't be found. Use dependencywalker to check. What do I do when I find these dependencies? Do I put them in some environment variable? Do I put them in site-packages along with the .pyd file, or in some other directory? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to correctly pass “pointer-to-pointer” i nto DLL via ctypes?
Thank you a lot! I have stripped down my production code to the sample - and it worked. Bug was in another part of my code where free() was called for the memory in question. On Fri, Nov 19, 2010 at 3:39 PM, Diez B. Roggisch wrote: > Grigory Petrov writes: > >> Hello. >> >> I have a DLL that allocates memory and returns it. Function in DLL is like >> this: >> >> void Foo( unsigned char** ppMem, int* pSize ) >> { >> * pSize = 4; >> * ppMem = malloc( * pSize ); >> for( int i = 0; i < * pSize; i ++ ) (* pMem)[ i ] = i; >> } >> >> Also, i have a python code that access this function from my DLL: >> >> from ctypes import * >> Foo = windll.mydll.Foo >> Foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] >> mem = POINTER( c_ubyte )() >> size = c_int( 0 ) >> Foo( byref( mem ), byref( size ) ] >> print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] >> >> I'm expecting that print will show "4 0 1 2 3" but it shows "4 221 221 >> 221 221" O_O. Any hints what i'm doing wrong? > > After correcting quite a few obvious errors in your code, it worked just > fine for me. So I guess what you think you test is not what you test. > > --- test.py > from ctypes import * > > foo = > cdll.LoadLibrary("/Users/deets/projects/GH28/kinect/kinect/c/foo/libtest.dylib").foo > foo.argtypes = [ POINTER( POINTER( c_ubyte ) ), POINTER( c_int ) ] > mem = POINTER( c_ubyte )() > size = c_int( 0 ) > foo( byref( mem ), byref( size ) ) > print size, mem[ 0 ], mem[ 1 ], mem[ 2 ], mem[ 3 ] > --- > > --- test.c > void foo( unsigned char** ppMem, int* pSize ) > { > int i; > * pSize = 4; > * ppMem = malloc( * pSize ); > for( i = 0; i < * pSize; i ++ ) (* ppMem)[ i ] = i; > } > --- > > --- CMakeLists.txt > cmake_minimum_required (VERSION 2.6) > project (Test) > add_library(test SHARED test.c) > --- > > -- > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the EAX register with Python
Well, I think using ptrace is really the best way, at least what I have found on Google told me that. Stefan, your answer will fit perfectlly for me, it was what I'm searching. Thank you On Nov 19, 10:43 am, David Cournapeau wrote: > On Fri, Nov 19, 2010 at 4:17 PM, Tim Roberts wrote: > > dutche wrote: > > >>Hi folks, I have a unusual question here. > > >>How can I change the value of EAX register under python under Linux?? > >>As paimei does under Windows. > > >>My project is to have a python program that loads a C program and sets > >>a breakpoint at some address, and then with this breakpoint I change > >>the EAX register and then continue the program execution. > > >>With Windows and paimei I did that, but under Linux I don't know yet. > > > You will need to find a Linux application equivalent to PaiMei. Your > > question is not "how can I change EAX", your question is "where can I find > > a Linux debugger that can be controlled from Python?" > > Well, gdb may just be the tool you are looking for: since version 7.0 > at least, you can script gdb using python, > > http://sourceware.org/gdb/wiki/PythonGdb > > cheers, > > David -- http://mail.python.org/mailman/listinfo/python-list
Re: Extension on Windows
Eric Frederich wrote: > Do I put them [DLL dependencies] in some environment variable? > Do I put them in site-packages along with the .pyd file, or in some > other directory? Take a look at the LoadLibrary() docs: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx These further lead on to: http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx which details in what order different places are searched for DLLs. If you put the DLL in the same directory as your PYD, it should work. This is not the most elegant solution though, see above for more info. Cheers! Uli -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Program, Application, and Software
On Fri, 19 Nov 2010 01:43:28 +0100, Alexander Kapps wrote: > What difference does it make? Is 'print "Hello"' a program or a script? > Are you saying, that it depends on whether you have to manually call > some compiler? Thats the way the term 'script' is usually used in the UNIX/Linux world. In that environment you'd call awk and Perl scripting languages but C and Java are known as compiled languages. The size of the source isn't relevant: if you can mark a source file as executable and simply run it its a 'script' while if it needs a separate preparatory step to generate a separate executable its just a source file for a compiled language. The distinction doesn't seem to be used in a Windows environment. Indeed, it doesn't make sense there since executables are limited to .BAR or .CMD files, which are directly interpreted by the command processor, and .EXE or .COM files, which must be compiled before they can be run. AFAIK there's no way you can mark anything else, such as an awk, Perl or Python source file, as executable since there is no 'executable' attribute in any Windows filing system. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list
Re: Bunch 2.0 - a dict with a default
On Nov 18, 8:45 pm, Phlip wrote: > Pythonistas: > > If everyone likes this post, then the code is a "snippet" for > community edification. Otherwise, it's a question: How to do this kind > of thing better? > > I want a dict() variant that passes these test cases: > > map = Map() > assert not(map.has_key('_default')) > > map = Map(yo='dude') > assert map['yo'] == 'dude' > assert map.yo == 'dude' > assert None == map['whatever'] > assert not(map.has_key('_default')) > > map = Map(yo='dude', _default='q') > assert 'q' == map['whatever'] > assert not(map.has_key('_default')) > > That's like Bunch, but with a default value. (That makes code with > excess if statements less likely.) > > So here's the implementation: > > def Map(*args, **kwargs): > value = kwargs.get('_default', None) > if kwargs.has_key('_default'): del kwargs['_default'] > > class _DefMap(dict): > def __init__(self, *a, **kw): > dict.__init__(self, *a, **kw) > self.__dict__ = self > > def __getitem__(self, key): > if not self.has_key(key): self[key] = value > return dict.__getitem__(self, key) > > return _DefMap(*args, **kwargs) > > -- > Phlip > http://bit.ly/ZeekLand Looks like some combination of defaultdict and namedtuple. -- http://mail.python.org/mailman/listinfo/python-list
Re: regenerating unicodedata for py2.7 using py3 makeunicodedata.py?
2010/11/18 Martin v. Loewis : > >> Thanks for the confirmation Martin! >> >> Do you think, it the mentioned omission of the character names of some >> CJK ranges in unicodedata intended, or should it be reported to the >> tracker? > > It's certainly a bug. So a bug report would be appreciated, but much > more so a patch. Ideally, the patch would either be completely > forward-compatible (should the CJK ranges change in future Unicode > versions), > or at least have a safe-guard to detect that the data file is getting > out of sync with the C implementation. > > Regards, > Martin > Thanks, I just created a bug ticket: http://bugs.python.org/issue10459 The omissions of character names seem to be: 龼 (0x9fbc) - 鿋 (0x9fcb) (CJK Unified Ideographs [19968-40959] [0x4e00-0x9fff]) 𪜀 (0x2a700) - 𫜴 (0x2b734) (CJK Unified Ideographs Extension C [173824-177983] [0x2a700-0x2b73f]) 𫝀 (0x2b740) - 𫠝 (0x2b81d) (CJK Unified Ideographs Extension D [177984-178207] [0x2b740-0x2b81f]) (Also the unprintable ASCII controls, Surrogates and Private use area, where the missing names are probably ok.) Unfortunately, I am not able to provide a patch, mainly because of unicodadate being C code. A while ago I considered writing some unicodedata enhancements in python, which would support the ranges and script names, full category names etc., but sofar the direct programatic lookups in the online unicode docs and with some simple processing also do work sufficiently... Regards, Vlastimil Brom -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run an EXE, with argument, capture output value
Any other help? I am guessing not, just wanted to try one more time. Could really use help, please!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extension on Windows
On Fri, Nov 19, 2010 at 8:12 AM, Ulrich Eckhardt wrote: > Eric Frederich wrote: >> Do I put them [DLL dependencies] in some environment variable? >> Do I put them in site-packages along with the .pyd file, or in some >> other directory? > > Take a look at the LoadLibrary() docs: > http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx > > These further lead on to: > http://msdn.microsoft.com/en-us/library/ms682586(v=VS.85).aspx > which details in what order different places are searched for DLLs. > > If you put the DLL in the same directory as your PYD, it should work. This > is not the most elegant solution though, see above for more info. > Well... I used the tool and found missing dependencies and just copied them into site-packages. There were two. Then when I put those two in there and ran dependencywalker again, I had 6 more missing. I found all of these dependencies in a "bin" directory of the program which I'm trying to create bindings for. The one I couldn't find was MSVCR80.DLL but my python module imported fine so maybe its not a big deal (actually, if I throw one of their dll files into dependency walker it shows the same thing). This was just with me wrapping one (very basic) routine. I would imagine as I wrap more and more, I'd need more and more dll files. I think rather than copying .dll files around, I'll just put my .pyd file in their 'bin' directory and set PYTHONPATH environment variable. Things are starting to look promising. I now have to deal with other issues (coming up in a new python-list thread). Thanks a bunch Ulri. -- http://mail.python.org/mailman/listinfo/python-list
Re: Program, Application, and Software
Am 19.11.2010 15:22, schrieb Martin Gregorie: On Fri, 19 Nov 2010 01:43:28 +0100, Alexander Kapps wrote: What difference does it make? Is 'print "Hello"' a program or a script? Are you saying, that it depends on whether you have to manually call some compiler? Thats the way the term 'script' is usually used in the UNIX/Linux world. In that environment you'd call awk and Perl scripting languages but C and Java are known as compiled languages. The size of the source isn't relevant: if you can mark a source file as executable and simply run it its a 'script' while if it needs a separate preparatory step to generate a separate executable its just a source file for a compiled language. The distinction doesn't seem to be used in a Windows environment. Indeed, it doesn't make sense there since executables are limited to .BAR or .CMD files, which are directly interpreted by the command processor, and .EXE or .COM files, which must be compiled before they can be run. AFAIK there's no way you can mark anything else, such as an awk, Perl or Python source file, as executable since there is no 'executable' attribute in any Windows filing system. Not in the file system, but in the environment it is definitely possible. One might try http://www.google.de/search?q=pathext or just have a look at http://wiki.tcl.tk/1785 (the respective filetype has to be associated with it's interpreter however for this method to work.) Josef -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the precision of fractions.Fraction?
Does Fractions remove common factors the way it should? If it does and you want to find the closest fraction with a smaller denominator i think tou'll need some number theory and continued fractions. RJB On Nov 18, 8:26 pm, Steven D'Aprano wrote: > On Thu, 18 Nov 2010 20:08:00 +0100, Stefan Sonnenberg-Carstens wrote: > > If you need it really *precise*, cast your Fractions into type Decimal: > > It's actually the opposite. Decimal has many advantages, but being > "really precise" is not one of them. It suffers the exact same issues re > precision and round-off as binary floating point. > > It is easy to demonstrate that there are numbers which cannot be > represented precisely as Decimals no matter how many decimal places you > use, but can be represented exactly as Fractions. Fraction can exactly > represent every Decimal, but Decimal cannot represent exactly every > Fraction. > > We're not talking about weird edge cases either, but simple numbers that > you're likely to come across every day: > > >>> from decimal import Decimal > >>> one_ninth = Decimal(1)/Decimal(9) > >>> two_thirds = Decimal(2)/Decimal(3) > >>> one_ninth*6 == two_thirds > > False > > >>> from fractions import Fraction > >>> one_ninth = Fraction(1, 9) > >>> two_thirds = Fraction(2, 3) > >>> one_ninth*6 == two_thirds > > True > > Still not convinced? > > >>> f = Fraction(1) + Fraction(1, 10**10) > >>> f != 1 > > True > > (which is virtually instantaneous, by the way) > > compared to the *much* slower: > > >>> d = Decimal(1) + Decimal(1)/Decimal(10**10) > >>> d != 1 > > False > > Yes, I could try to set the Decimal context to 100,000 decimal places -- > and just as easily defeat it again by adding one more to the exponent. > > In my opinion, the Fraction module is one of the least appreciated and > underused modules in the standard library -- and I include myself in > that. It really is a joy, and I don't use it anywhere near enough. > > -- > Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the EAX register with Python
On 11/19/10 7:08 AM, dutche wrote: Well, I think using ptrace is really the best way, at least what I have found on Google told me that. You may also want to look into pinktrace for another wrapper around ptrace. I haven't used it myself, but it's worth looking into. http://dev.exherbo.org/~alip/pinktrace/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: What was your strategy?
In article <7xr5ei1p2j@ruckus.brouhaha.com>, Paul Rubin wrote: > Lou Pecora writes: > >> > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. > >> It's encyclopedic. > > Indeed. I hope Martelli updates it. I'd buy another copy right away. > > It's a great book but not a starting point for beginners. It's > definitely worth having for more advanced users. I would beg to differ. I used it from the start of my Python learning curve and was greatly helped by it. For me it gave explanations at just the right level with paths to more detail if you wanted. I found it helpful from the beginning. I would recommended others to at least look at it. You might be helped right away and it's a good addition to any Python programmer's library. -- -- Lou Pecora -- http://mail.python.org/mailman/listinfo/python-list
Round Trip: C to Python to C Module
I have a proprietary software PropSoft that I need to extend. They support extensions written in C that can link against PropLib to interact with the system. I have a Python C module that wraps a couple PropLib functions that I call PyProp. >From an interactive Python shell I can import PyProp and call a function. None of these functions really do anything outside the context of being logged into the PropSoft software; so all the functions fail when running from Python alone. To my amazement, I was able to run PyRun_SimpleString("import PyProp\nPyProp.some_function()") without setting PYTHONPATH or anything. How this works, I don't know and I don't really care (at the moment anyway). The problem I'm having now is how do I return things from my Python script back to C? Ultimately I won't be hard coding python inside of PyRun_SimpleString but loading the script from a file. So, how do I return values back to C? Python functions return values but running a python script?... doesn't that just have an exit status? Is there a mechanism for doing this? Thanks in advance, ~Eric -- http://mail.python.org/mailman/listinfo/python-list
ANN: PyGUI 2.3.1
PyGUI 2.3.1 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ This version incorporates a modification that I hope will improve the behaviour of ScrollableViews on Windows with pywin32 builds later than 212. (There are still problems with it, though. If the Scrollable View doesn't fill all of its containing window, the scroll bars get repositioned incorrectly when the window is resized. This appears to be entirely MFC's doing. I really will have to get away from using CView altogether.) This version also fixes a problem on Windows whereby dismissing a modal dialog with the Return key could spuriously activate a button in another window. What is PyGUI? -- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ew...@canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the EAX register with Python
On 2010-11-19, Tim Roberts wrote: > dutche wrote: >> My project is to have a python program that loads a C program and >> sets a breakpoint at some address, and then with this breakpoint I >> change the EAX register and then continue the program execution. > You will need to find a Linux application equivalent to PaiMei. Your > question is not "how can I change EAX", your question is "where can I > find a Linux debugger that can be controlled from Python?" > > I don't know the answer to that. gdb is quite powerful, and you can > certainly control it by connecting to its stdin and stdout > connections. If you're going to do that, you want to run gdb in "machine interface" mode, which makes it a lot easier to talk to programatically. I've not done it in Python, but it's easy enough in C, so in Python it ought to be trivial: http://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI.html#GDB_002fMI If you don't want to write code to talk the gdb/mi "command language", then another option is to use a library like libmigdb: http://sourceforge.net/projects/libmigdb/ You can probably call the library functions using cytpes: http://docs.python.org/library/ctypes.html -- Grant Edwards grant.b.edwardsYow! Psychoanalysis?? at I thought this was a nude gmail.comrap session!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: What was your strategy?
On 11/19/2010 10:55 AM, Lou Pecora wrote: > In article <7xr5ei1p2j@ruckus.brouhaha.com>, > Paul Rubin wrote: > >> Lou Pecora writes: > I'll jump in and recommend the book "Python in a Nutshell" by Martelli. It's encyclopedic. >>> Indeed. I hope Martelli updates it. I'd buy another copy right away. >> >> It's a great book but not a starting point for beginners. It's >> definitely worth having for more advanced users. > > I would beg to differ. I used it from the start of my Python learning > curve and was greatly helped by it. For me it gave explanations at just > the right level with paths to more detail if you wanted. I found it > helpful from the beginning. I would recommended others to at least look > at it. You might be helped right away and it's a good addition to any > Python programmer's library. > I'd say "Nushell" is a great book for experienced programmers, whether in Python or other languages. It's definitely not something I would recommend for a programming noob. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run an EXE, with argument, capture output value
On Fri, Nov 19, 2010 at 9:52 AM, noydb wrote: > Any other help? I am guessing not, just wanted to try one more time. > Could really use help, please!! You'll need to give us more information about the program you're trying to automate. It originally sounded like you just needed to run a console program, where it's usually fairly easy to run and capture the output with the subprocess module. Now it sounds like you're trying to automate a GUI that requires user interaction. That's quite a bit more complicated. When you run "stats_hall.exe", what do you get on the screen? What, exactly, are the steps a normal user would need to perform to do what you want to automate? After the values you're interested in are computed, where do they show up? Is this program publically available someplace? I've generally had good luck doing simple GUI automation with pywinauto. The homepage appears to be: http://pywinauto.pbworks.com which has installation instructions and a FAQ. You might also find this demo useful: http://showmedo.com/videotutorials/video?name=UsingpyWinAutoToControlAWindowsApplication -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Program, Application, and Software
On 11/19/2010 9:22 AM, Martin Gregorie wrote: [...] > Indeed, > it doesn't make sense there since executables are limited to .BAR or .CMD > files, which are directly interpreted by the command processor, and .EXE > or .COM files, which must be compiled before they can be run. AFAIK > there's no way you can mark anything else, such as an awk, Perl or Python > source file, as executable since there is no 'executable' attribute in > any Windows filing system. Under Windows you use the PATHEXT mechanism to mark an extension as executable. Then finding a file with that extension on the PATH will trigger it to be run by the registered interpreter. As far as I know, anyway. By default on my Vista system I see PATHEXT contains C:\Users\sholden\workspace\Python3_Lesson3\src>echo %PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Modifying Element In For List
Am 15.11.2010 18:27, schrieb Duncan Booth: > Comparing directly against True or False is error prone: a value in > Python can be false without actually being equal to False. Well, you can always use "is" instead of "==", which makes a comparison to True or False perfectly safe. Regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa -- http://mail.python.org/mailman/listinfo/python-list
Re: Modifying Element In For List
On 11/19/2010 12:17 PM, Johannes Bauer wrote: > Am 15.11.2010 18:27, schrieb Duncan Booth: > >> Comparing directly against True or False is error prone: a value in >> Python can be false without actually being equal to False. > > Well, you can always use "is" instead of "==", which makes a comparison > to True or False perfectly safe. > But it's still the wrong thing to do. if condition==True: and if condition is True: should both be replaced (under most circumstances) by if condition: regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
On 11/16/2010 9:12 AM, Arnaud Delobelle wrote: > Hrvoje Niksic writes: > >> m...@distorted.org.uk (Mark Wooding) writes: >> So even if the globals() dictionary is custom, its __setitem__ method is *not* called. >>> >>> Fascinating. Thank you. >> >> In case it's not obvious, that is because CPython assumes the type for >> many of its internal or semi-internal structures, and calls the >> appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) >> directly. So python doesn't break the encapsulation of dict itself, it >> just takes the liberty to assume that globals() is a non-subclassed >> dict, at least as far as __setitem__ is concerned. > > But it doesn't make this assumption for locals(). > That's because it reserves the right to optimize local storage without extending the mapping to allowing item setting. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the precision of fractions.Fraction?
On Fri, 19 Nov 2010 07:29:59 -0800 (PST), RJB wrote: > Does Fractions remove common factors the way it should? > > If it does and you want to find the closest fraction with a smaller > denominator i think tou'll need some number theory and continued > fractions. No heroics required, finding the greatest common divisor is fast. And if this simple test is indicative, the fractions module reduces: >>> x = fractions.Fraction( 2**100, 3 ) >>> y = fractions.Fraction( 7, 2**101 ) >>> z = x * y >>> print x._numerator, x._denominator 1267650600228229401496703205376 3 >>> print y._numerator, y._denominator 7 2535301200456458802993406410752 >>> print z._numerator, z._denominator 7 6 -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run an EXE, with argument, capture output value
C:\Documents and Settings\Tim Harig\My Documents\autoCalc>dir Volume in drive C has no label. Volume Serial Number is 30D9-35E0 Directory of C:\Documents and Settings\Tim Harig\My Documents\autoCalc 11/19/2010 12:20 PM . 11/19/2010 12:20 PM .. 11/19/2010 12:19 PM 686 autoCalc.pys 1 File(s)686 bytes 2 Dir(s) 16,343,552,000 bytes free C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type autoCalc.pys # autoCalc.pys: The "pys" extension indicates that it should be run under # Windows Script Host # perform the calculation using Windows calculator keySequence = ['2', '{+}', '2', '=', '^c', '%{F4}'] WshShell = WScript.CreateObject("WScript.Shell") calculator = WshShell.Run("calc") WshShell.AppActivate("calc") WScript.Sleep(1000) for currentKey in keySequence: WshShell.SendKeys(currentKey) WScript.Sleep(100) # write the results to notepad and same as demo.txt keySequence = ['result: ', '^v', '^s', 'c:\\Documents and Settings\\Tim Harig\\My Documents\\autoCalc\\demo.txt', '~', '%{F4}'] notepad = WshShell.Run("notepad") WshShell.AppActivate("notepad") WScript.Sleep(1000) for currentKey in keySequence: WshShell.SendKeys(currentKey) WScript.Sleep(100) C:\Documents and Settings\Tim Harig\My Documents\autoCalc>cscript.exe autoCalc.pys Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. Debugging extensions (axdebug) module does not exist - debugging is disabled.. C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type demo.txt result: 4 C:\Documents and Settings\Tim Harig\My Documents\autoCalc> -- http://mail.python.org/mailman/listinfo/python-list
Re: Round Trip: C to Python to C Module
Eric Frederich writes: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp. >>From an interactive Python shell I can import PyProp and call a function. > None of these functions really do anything outside the context of > being logged into the PropSoft software; so all the functions fail > when running from Python alone. > > To my amazement, I was able to run PyRun_SimpleString("import > PyProp\nPyProp.some_function()") without setting PYTHONPATH or > anything. How this works, I don't know and I don't really care (at > the moment anyway). > > The problem I'm having now is how do I return things from my Python > script back to C? > Ultimately I won't be hard coding python inside of PyRun_SimpleString > but loading the script from a file. > So, how do I return values back to C? Python functions return values > but running a python script?... doesn't that just have an exit status? > Is there a mechanism for doing this? You write an extension in C that embeds a Python-interpreter. That interpreter then loads your script, and executes it. Let's say the PropSoft offers you three functions for a custom extension. void init(); int do_something(int); void cleanup(); Then you write a C-extension that contains these three function calls, and in init, you create a Python-interpreter and load your script. It should offer a "do_something_in_python" method that takes an int and returns one. In do_something, you invoke the aforementioned do_something_in_python function through the Python C-API as described. In cleanup, you do what the function name says. Possibly the use of elmer[1] makes the whole process easier. [1]: http://wiki.python.org/moin/elmer -- Diez -- http://mail.python.org/mailman/listinfo/python-list
Module locale throws exception: unsupported locale setting
Hello, on a german Windows installation I get problems with locale. If I run that module as a script from a command window this is the output: C:\Python31\Lib>locale.py Locale aliasing: Locale defaults as determined by getdefaultlocale(): Language: de_DE Encoding: cp1252 Locale settings on startup: LC_NUMERIC ... Language: (undefined) Encoding: (undefined) LC_MONETARY ... Language: (undefined) Encoding: (undefined) LC_COLLATE ... Language: (undefined) Encoding: (undefined) LC_CTYPE ... Language: (undefined) Encoding: (undefined) LC_TIME ... Language: (undefined) Encoding: (undefined) Locale settings after calling resetlocale(): Traceback (most recent call last): File "C:\Python31\Lib\locale.py", line 1798, in _print_locale() File "C:\Python31\Lib\locale.py", line 1761, in _print_locale resetlocale() File "C:\Python31\Lib\locale.py", line 537, in resetlocale _setlocale(category, _build_localename(getdefaultlocale())) locale.Error: unsupported locale setting C:\Python31\Lib> This is Windows 7, 64 bit, Python 3.1.2. Same behavior on another Windows machine with Python 2.7 (Windows XP, 32 bit). On Linux, using UTF-8 as system character set and Python 2.6, 2.6.5 or 3.1.2, no problems using locale, running the module as a script gives no exception but the expected output. So I suppose it's either an OS problem or connected with the encoding. I've looked into bugs.python.org, but found only vaguely similar issues. Should I open a new one? Thank you for help, Sibylle -- http://mail.python.org/mailman/listinfo/python-list
Re: Module locale throws exception: unsupported locale setting
In article , Sibylle Koczian wrote: > on a german Windows installation I get problems with locale. If I run > that module as a script from a command window this is the output: > > C:\Python31\Lib>locale.py > Locale aliasing: > > Locale defaults as determined by getdefaultlocale(): > > Language: de_DE > Encoding: cp1252 > > Locale settings on startup: > > LC_NUMERIC ... > Language: (undefined) > Encoding: (undefined) > > LC_MONETARY ... > Language: (undefined) > Encoding: (undefined) > > LC_COLLATE ... > Language: (undefined) > Encoding: (undefined) > > LC_CTYPE ... > Language: (undefined) > Encoding: (undefined) > > LC_TIME ... > Language: (undefined) > Encoding: (undefined) > > > Locale settings after calling resetlocale(): > > Traceback (most recent call last): >File "C:\Python31\Lib\locale.py", line 1798, in > _print_locale() >File "C:\Python31\Lib\locale.py", line 1761, in _print_locale > resetlocale() >File "C:\Python31\Lib\locale.py", line 537, in resetlocale > _setlocale(category, _build_localename(getdefaultlocale())) > locale.Error: unsupported locale setting > > C:\Python31\Lib> > > This is Windows 7, 64 bit, Python 3.1.2. Same behavior on another > Windows machine with Python 2.7 (Windows XP, 32 bit). > > On Linux, using UTF-8 as system character set and Python 2.6, 2.6.5 or > 3.1.2, no problems using locale, running the module as a script gives no > exception but the expected output. So I suppose it's either an OS > problem or connected with the encoding. > > I've looked into bugs.python.org, but found only vaguely similar issues. > Should I open a new one? There have been a lot of changes going into Python 3.2, currently in alpha testing, in the areas of encodings and how they affect the interfaces to/from the various platform operating systems Python 3 runs on. It would be very useful if you could try the same test with the most recent Python 3.2 alpha (http://www.python.org/download/releases/3.2/) and, if the problem persists there, open an issue about it. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribution of Python Scripts
So, what's my options. Maybe this page can give some inspiration? http://wiki.python.org/moin/deployment -- http://mail.python.org/mailman/listinfo/python-list
Earn in Management careers.
On Management careers base, Earn monthly. Supporting Management careers. http://managementjobs.webs.com/pm.htm & http://topcareer.webs.com/humanresourcemgmt.htm Offers for job seekers Opportunities for you Make your career. http://rojgars1.webs.com/gov.htmhttp://rojgars.webs.com/bankingjobs.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavor....
Hrvoje Niksic writes: > m...@distorted.org.uk (Mark Wooding) writes: > >>> So even if the globals() dictionary is custom, its __setitem__ method is >>> *not* called. >> >> Fascinating. Thank you. > > In case it's not obvious, that is because CPython assumes the type for > many of its internal or semi-internal structures, and calls the > appropriate functions, such as dict.__setitem__ (PyDict_SetItem in C) > directly. So python doesn't break the encapsulation of dict itself, it > just takes the liberty to assume that globals() is a non-subclassed > dict, at least as far as __setitem__ is concerned. But it doesn't make this assumption for locals(). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run an EXE, with argument, capture output value
Thanks to Jerry Hill above who helped. This worked: from pywinauto.application import Application app = Application() app.start_(r'C:\temp\hallbig2.exe') app.Form1.Edit6.TypeKeys(r'C:\temp\input\Ea39j.txt') E_Value = "" while (E_Value == ""): app.Form1.Compute.Click() E_Value = app.Form1.Edit8.WindowText() print repr(E_Value) app.Kill_() -- http://mail.python.org/mailman/listinfo/python-list
dict diff
so i came up with a diff method to compare 2 dicts. i found it pretty useful so i thought i'd share it with everyone. you can see the doctest to check out suggested uses. since we can't modify built-ins, i demonstrated adding a diff method to OrderedDict to show how one could add it to your own mapping objects. the core logic is compatible with python2 and 3 (i've only tested using 2.6.5 and 3.1.2). the doctest is suited for python3 though. the interface is pretty straightforward. it would be awesome to have this sucker as a method on the builtin dict, but that'd take a pep, no? -- Jin Yi __author__ = 'razamatan_retral_net_ignore_com' from collections import Mapping def diffdict(left, right): ''' returns the deep diff of two dicts. the return value the tuple (left_diff, right_diff) >>> diffdict(1, None) (1, None) >>> diffdict({1:2}, None) ({1: 2}, None) >>> diffdict({1:2}, {3:4}) ({1: 2, 3: }, {1: , 3: 4}) >>> from collections import OrderedDict >>> x = OrderedDict({1:2, 3:{4:{5:[6,7], 8:9}}}) >>> diffdict(x, x) (None, None) >>> y = {1:2, 3:[4]} >>> diffdict(x, y) ({3: {4: {8: 9, 5: [6, 7]}}}, {3: [4]}) >>> y = {1:2, 3:{4:{5:[6,7]}}} >>> diffdict(x, y) ({3: {4: {8: 9}}}, {3: {4: {8: }}}) >>> y = {1:2, 3:{4:{5:{6:7}, 8:9}}} >>> diffdict(x, y) ({3: {4: {5: [6, 7]}}}, {3: {4: {5: {6: 7) >>> del y[3] >>> diffdict(x, y) ({3: {4: {8: 9, 5: [6, 7]}}}, {3: }) >>> y = {1:2, 3:{4:{5:[6,10], 8:9}}} >>> diffdict(x, y) ({3: {4: {5: [6, 7]}}}, {3: {4: {5: [6, 10]}}}) >>> y = {1:100, 3:{4:{5:[6,7], 8:9}}} >>> diffdict(x, y) ({1: 2}, {1: 100}) >>> diffdict(y, x) ({1: 100}, {1: 2}) >>> x.__class__.diff = diffdict >>> x.__class__.__xor__ = diffdict >>> x.diff(x) (None, None) >>> x ^ y ({1: 2}, {1: 100}) ''' # base case if not isinstance(left, Mapping) or not isinstance(right, Mapping): return (left, right) # key exclusivity left_diff = dict(i for i in left.items() if i[0] not in right) right_diff = dict(i for i in right.items() if i[0] not in left) right_diff.update((k, KeyError) for k in left_diff if k not in right_diff) left_diff.update((k, KeyError) for k in right_diff if k not in left_diff) # value differences for k in (k for k in left if k in right): if left[k] != right[k]: (ld, rd) = diffdict(left[k], right[k]) left_diff[k] = ld or None right_diff[k] = rd or None left_diff = left_diff or None right_diff = right_diff or None return (left_diff, right_diff) -- http://mail.python.org/mailman/listinfo/python-list
try to use unicode
Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'Månadslön:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'Månadslön:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael -- http://mail.python.org/mailman/listinfo/python-list
Re: dict diff
On 11/19/2010 8:58 PM, Jin Yi wrote: > so i came up with a diff method to compare 2 dicts. i found it pretty > useful so i thought i'd share it with everyone. you can see the doctest > to check out suggested uses. since we can't modify built-ins, i > demonstrated adding a diff method to OrderedDict to show how one could > add it to your own mapping objects. > > the core logic is compatible with python2 and 3 (i've only tested using > 2.6.5 and 3.1.2). the doctest is suited for python3 though. > > > the interface is pretty straightforward. it would be awesome to have > this sucker as a method on the builtin dict, but that'd take a pep, no? > > > A PEP *and* some explanation of why you would want such an obscure piece of code built in to the dict object, yes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: dict diff
i don't think this piece of code is obscure. i think the use case is there when you know that dicta != dictb, but you need to know where they're different. i wouldn't really care to have it on the dict since it's useful as an unbound method anyway. On Sat, Nov 20, 2010 at 01:11:53AM -0500, Steve Holden wrote: > On 11/19/2010 8:58 PM, Jin Yi wrote: > > so i came up with a diff method to compare 2 dicts. i found it pretty > > useful so i thought i'd share it with everyone. you can see the doctest > > to check out suggested uses. since we can't modify built-ins, i > > demonstrated adding a diff method to OrderedDict to show how one could > > add it to your own mapping objects. > > > > the core logic is compatible with python2 and 3 (i've only tested using > > 2.6.5 and 3.1.2). the doctest is suited for python3 though. > > > > > > the interface is pretty straightforward. it would be awesome to have > > this sucker as a method on the builtin dict, but that'd take a pep, no? > > > > > > > A PEP *and* some explanation of why you would want such an obscure piece > of code built in to the dict object, yes. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon 2011 Atlanta March 9-17 http://us.pycon.org/ > See Python Video! http://python.mirocommunity.org/ > Holden Web LLC http://www.holdenweb.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: try to use unicode
Am 20.11.2010 06:53, schrieb Mikael B: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'Månadslön:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'Månadslön:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. <>-- http://mail.python.org/mailman/listinfo/python-list
RE: try to use unicode
Date: Sat, 20 Nov 2010 08:47:18 +0100 From: stefan.sonnenb...@pythonmeister.com To: mba...@live.se CC: python-list@python.org Subject: Re: try to use unicode Meddelandetext Am 20.11.2010 06:53, schrieb Mikael B: Hi. I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use unicode to get swedish characters. I've checked wikipedia. utf-8 is said to be an unicode encoding.. this is the test program: # -*- coding: utf-8 -*- import readline s=raw_input(u'Månadslön:') and this is the output: Traceback (most recent call last): File "test_uni.py", line 5, in s=raw_input(u'Månadslön:') UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128) I'm doing something wrong... Mikael Your console is not unicode ready. Please take a look at the locale command and vars like LC_ALL, LC_LANG etc. Aha... Ok,thank you -- http://mail.python.org/mailman/listinfo/python-list