Re: New member intro and question
Hi Anthony, Welcome to the python users mailing list. On Sat, Jun 18, 2011 at 9:32 AM, Anthony Papillion wrote: > Hi Everyone, > > > I'm a new list member from the United States. Long time programmer, > fairly new to Python and absolutely loving it so far! I'm 36, live in > Oklahoma, and own a small Linux software development and consulting > firm. Python has made my life a *lot* easier and, the more I learn, > the easier it gets. Simply blown away. > > > Now, for my question: I'm taking on a project that will run on plug > computers and I'm thinking about using Python to do it. It seems like > a really attractive option over C/C++ and I think it would cut down > the dev time immensely. I know a scaled down version of Debian can run > on the computer but I'm wondering about Python. > > Has anyone ever used Python to develop for extremely limited resource > computers like this? Specifically, I'm going to be using the DreamPlug > (http://www.geek.com/articles/gadgets/dreamplug-puts-a-1-2ghz-arm-pc-in-a-power-outlet-2011022/) > which isn't too shabby but I wonder if it will work. > >From the link you've given, I see that the device has a 1.2GHz ARM processor and 512M RAM. That doesn't sound like an extremely limited resource device. Python runs very well on a Nokia N900, for example, which has a 600MHz ARM processor and 256M RAM (from memory, might not be exact). -- regards, kushal -- http://mail.python.org/mailman/listinfo/python-list
Re: integer to binary 0-padded
>>> '{:+#0{}b}'.format(255, 1 + 2 + 16) +0b >>> '{:+#0{}b}'.format(-255, 1 + 2 + 16) -0b >>> >>> eval('{:+#0{}b}'.format(255, 1 + 2 + 16)) 255 >>> eval('{:+#0{}b}'.format(-255, 1 + 2 + 16)) -255 >>> jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyGUI 2.5
Terry Reedy wrote: Greg left out the most important to me: "Now works with Python 3 on MacOSX and Windows!" I'm not making too much of that at the moment, because it *doesn't* work on Linux yet, and I've no idea how long it will be before it does. The issue is that there will apparently not be any Python 3 version of pygtk, on the grounds that gobject introspection can be used instead. Unfortunately, Gtk 3 and related libraries don't quite handle gobject introspection well enough to support PyGUI at the moment. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyGUI 2.5
Wolfgang Keller wrote: Any chance to see a hierarchical multi-column TreeListView anytime soon? There may be a table view, but I can't promise anything about a tree view, sorry. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in a shell script
Thank you, everyone, for your suggestions. I'll try them all and decide which I like best. -- http://mail.python.org/mailman/listinfo/python-list
Re: break in a module
On Sat, Jun 18, 2011 at 2:49 PM, Steven D'Aprano wrote: > Not quite. In my config language, "ignored" means ignored. There was no > way of accessing the rest of the file, short of guessing the file name, > opening it and reading it as text. > > In Perl, the __END__ and __DATA__ keywords mark the end of the Perl > program, and leave the rest of the document visible to the caller via a > special file handle: Sure, but if you don't use that handle, it comes to the same thing. It's like a function's return value when you just want its side effects, or using re.match and ignoring all but whether it evaluates as True or False. In REXX, you can access any part of the source file using the sourceline() function - sometimes I've done things like this: /* Usage: scriptname [arg] [arg] [arg] arg: specifies the number of times to yell Argh arg: specifies the type of black beast to kill you arg: chooses an Abstract Resource Group Use this only in cases of blargh. */ . . . . usage: do i=2 to sourceline() until sourceline(i)="*/"; say sourceline(i); end Does this mean that the comment isn't ignored? Nope. It's ignored, but it can be retrieved through in-language means. Anyhow, it's not uncommon to abuse language features to do different things. I've heard that it's faster in MS-DOS Batch to put comments with a leading colon (making them labels for goto) than to use the REM (remark) command... ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best way to write this base class?
On Sat, Jun 18, 2011 at 2:17 PM, John Salerno wrote: > 1) > class Character: > > def __init__(self, name, base_health=50, base_resource=10): > self.name = name > self.health = base_health > self.resource = base_resource If you expect to override the health/resource, I'd use this model. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: break in a module
On Sat, 18 Jun 2011 14:31:51 +1000, Chris Angelico wrote: > On Sat, Jun 18, 2011 at 1:50 PM, Steven D'Aprano > wrote: >> I don't think the use-case for this is convincing enough to need it, >> but it's an interesting concept. I once played around with a >> mini-language for config files that included a "STOP" command, so that: >> >> key = value >> STOP >> everything under here is ignored >> >> > Isn't that how Perl's __data__ keyword works? (Long time since I've used > it, it mightn't be quite __data__.) Not quite. In my config language, "ignored" means ignored. There was no way of accessing the rest of the file, short of guessing the file name, opening it and reading it as text. In Perl, the __END__ and __DATA__ keywords mark the end of the Perl program, and leave the rest of the document visible to the caller via a special file handle: http://www.perl-programming.info/difference-btw-__end__-and-__data__ You know, I actually kinda like that... -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: break in a module
On Sat, Jun 18, 2011 at 1:50 PM, Steven D'Aprano wrote: > I don't think the use-case for this is convincing enough to need it, but > it's an interesting concept. I once played around with a mini-language > for config files that included a "STOP" command, so that: > > key = value > STOP > everything under here is ignored > Isn't that how Perl's __data__ keyword works? (Long time since I've used it, it mightn't be quite __data__.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
What's the best way to write this base class?
Let's say I'm writing a game (really I'm just practicing OOP) and I want to create a "Character" base class, which more specific classes will subclass, such as Warrior, Wizard, etc. Which of the following ways is better, or is there another way? Note: I have in mind that when a specific subclass (Warrior, Wizard, etc.) is created, the only argument that will ever be passed to the __init__ method is the name. The other variables will never be explicitly passed, but will be set during initialization. With that in mind, here are the ways I've come up with: 1) class Character: def __init__(self, name, base_health=50, base_resource=10): self.name = name self.health = base_health self.resource = base_resource 2) class Character: base_health = 50 base_resource = 10 def __init__(self, name): self.name = name self.health = base_health self.resource = base_resource 3) BASE_HEALTH = 50 BASE_RESOURCE = 10 class Character: def __init__(self, name): self.name = name self.health = BASE_HEALTH self.resource = BASE_RESOURCE -- http://mail.python.org/mailman/listinfo/python-list
New member intro and question
Hi Everyone, I'm a new list member from the United States. Long time programmer, fairly new to Python and absolutely loving it so far! I'm 36, live in Oklahoma, and own a small Linux software development and consulting firm. Python has made my life a *lot* easier and, the more I learn, the easier it gets. Simply blown away. Now, for my question: I'm taking on a project that will run on plug computers and I'm thinking about using Python to do it. It seems like a really attractive option over C/C++ and I think it would cut down the dev time immensely. I know a scaled down version of Debian can run on the computer but I'm wondering about Python. Has anyone ever used Python to develop for extremely limited resource computers like this? Specifically, I'm going to be using the DreamPlug (http://www.geek.com/articles/gadgets/dreamplug-puts-a-1-2ghz-arm-pc-in-a-power-outlet-2011022/) which isn't too shabby but I wonder if it will work. Thanks! Anthony Papillion -- http://mail.python.org/mailman/listinfo/python-list
Re: break in a module
On Sat, 18 Jun 2011 12:36:42 +1000, Cameron Simpson wrote: > On 17Jun2011 06:00, Steven D'Aprano > wrote: | If we were to have a > "exit this module early, but without exiting Python | altogether" > statement, I'd consider "exit" to be the most descriptive | name, > although it would clash with existing uses of the word, e.g. | > sys.exit(). Overloading "break" strikes me as disagreeable, but not as | > disagreeable as overloading "return" or "in" :) > > Just to throw another approach into the mix (because I was thinking > about the "finally" word), what about: > > raise StopImport > > along the lines of generators' "raise StopIteration". > > Then the import machinery can catch it, no new keyword is needed and no > existing keyword needs feature creeping. The only problem is that the importing module needs to catch it, or else you get a traceback. The importer shouldn't need to care what goes in inside the module. Something like this: spam() if condition: exit # halt, stop, whatever ham() cheese() should be the equivalent to: spam() if not condition: ham() cheese() I don't think the use-case for this is convincing enough to need it, but it's an interesting concept. I once played around with a mini-language for config files that included a "STOP" command, so that: key = value STOP everything under here is ignored but I think it was a feature in search of a use. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.2 for Windows reports version as 2.7.0?
Hi Benjamin, > The file info is seems correct but I just checked the MSI and it's reporting that it's 2.7.2. How exactly are you running python.exe and IDLE- are you calling the full path, just calling "python" and using whichever python version is first on your path, or are you using an entry in the start menu? The only thing I can think of is that your 2.7.0 install is in a different location than your 2.7.2 install. So 2.7.2 installed correctly but you're still running the old one. Within the folder where the python.exe exists, I have tried the following, all of which report Python 2.7.0 vs. 2.7.2 python python.exe c:\python27 Confirming I'm running what I think I'm running: >>> import sys >>> sys.hexversion 34013424 >>> sys.executable 'C:\\Python27\\python.exe' >>> And confirming the exe files in my Python27 folder: Directory of C:\Python27 06/12/2011 03:09 PM26,624 python.exe 06/12/2011 03:06 PM27,136 pythonw.exe Anyone else having the same experience? Malcolm On Fri, Jun 17, 2011 at 5:55 PM, wrote: > Just installed the 32-bit version Python 2.7.2 for Windows via the > python-2.7.2.msi download. > > When I start Python via python.exe or Idle, the version info is reported as > 2.7.0 vs. 2.7.2. > -- http://mail.python.org/mailman/listinfo/python-list
Re: Fun and games with lambda
I would rate it as a great example of human ingenuity Lalit On Fri, Jun 17, 2011 at 9:40 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > If you've ever wondered what lambda and reduce are good for, run this one- > liner and wonder no more... > > (Be patient, it may take a few seconds to return.) > > # Python 2 version: > > print((lambda f:((lambda p:p[0]+'.'+p[1:])(str((lambda Q:2*Q[0]*Q[0]//Q > [3])((lambda F:(lambda S:f(lambda T,_:((T[0]+T[1])//2,S((T[0]*T[1])// > F),2*T[2],(T[3]-(T[2]*(((T[0]+T[1])//2)**2-(S((T[0]*T[1])//F))**2))//F)), > [0]*13,(F,(F*F)//S(2*F),2,F//2)))(lambda n:f(lambda x,_:(x-x//2+(n*F)// > (2*x)),[0]*15,n//2)))(10**(5010[:5000])))(reduce)) > > # Python 3 version: > > print((lambda f:((lambda p:p[0]+'.'+p[1:])(str((lambda Q:2*Q[0]*Q[0]//Q > [3])((lambda F:(lambda S:f(lambda T,_:((T[0]+T[1])//2,S((T[0]*T[1])// > F),2*T[2],(T[3]-(T[2]*(((T[0]+T[1])//2)**2-(S((T[0]*T[1])//F))**2))//F)), > [0]*13,(F,(F*F)//S(2*F),2,F//2)))(lambda n:f(lambda x,_:(x-x//2+(n*F)// > (2*x)),[0]*15,n//2)))(10**(5010[:5000])))(__import__ > ('functools').reduce)) > > > I can't take credit for this little beauty. It originally came from > Manuel Garcia, all I did was make it compatible with Python 3 and add > some additional, but trivial, obfuscation. > > See the original post here: > http://web.archiveorange.com/archive/v/5H3d1yQN5N15HEgOWHMx > > > > Encouraging-hatred-of-lambdas-for-fun-and-profit-ly y'rs, > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: installing NLTK
Hans Mulder wrote: should make you a member of the "admin" group. All sorted now - thanks for your help. -- Nige Danton - Replace the obvious with g.m.a.i.l -- http://mail.python.org/mailman/listinfo/python-list
Re: break in a module
On 17Jun2011 06:00, Steven D'Aprano wrote: | If we were to have a "exit this module early, but without exiting Python | altogether" statement, I'd consider "exit" to be the most descriptive | name, although it would clash with existing uses of the word, e.g. | sys.exit(). Overloading "break" strikes me as disagreeable, but not as | disagreeable as overloading "return" or "in" :) Just to throw another approach into the mix (because I was thinking about the "finally" word), what about: raise StopImport along the lines of generators' "raise StopIteration". Then the import machinery can catch it, no new keyword is needed and no existing keyword needs feature creeping. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ And it is not our part here to take thought only for a season, or for a few lives of Men, or for a passing age of the world.- Gandalf the grey -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
On Fri, 17 Jun 2011 13:53:10 -0700, SherjilOzair wrote: > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? if you're doing repeated insertions into an already sorted list, there's no question that the bisect module is the right way to do it. (Unless you have a very old version of Python, version 2.3 or older.) >>> from timeit import Timer >>> setup = """ ... L = list(range(1)) + list(range(10100, 3)) ... from bisect import insort ... def sort_insert(a, x): ... a.append(x) ... a.sort() ... """ >>> t_bisect = Timer("for i in range(1, 10100): insort(L, i)", setup) >>> t_sort = Timer("for i in range(1, 10100): sort_insert(L, i)", setup) >>> >>> t_sort.timeit(number=100) 19.430757999420166 >>> t_bisect.timeit(number=100) 0.3741610050201416 (For those unfamiliar with timeit, small numbers are faster.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: installing NLTK
On Fri, Jun 17, 2011 at 1:57 PM, Nige Danton wrote: > Hans Mulder wrote: >> On 17/06/11 21:58:53, Nige Danton wrote: >>> Mac OSX python 2.6.1: I'm trying to install the natural language toolkit >>> and following the instructions here www.NLTK.org/download I've downloaded >>> the PyYAML package and in a terminal window tried to install it. However > >> You're not really giving us enough information, so I'll just guess: > > Sorry. > >> Are you trying a command that begins with "sudo"? > > Good guess. Yes it's sudo python setup.py install > >> If so, then you user password should work, provided you're a member >> of the 'admin' group. To find out, type "groups" in a Terminal >> window. If the response does not include "admin" as a separate > > Ok, thanks. Tried that and the response does not include admin nor my user > name > >> word, then you''l have to ask someone to give you admin rights. > > It's a personal computer - there is no one to ask. > > When I try my user password the reply is that it's not in the sudoers file > and the admin password it just rejects. Any idea what I should do? > > -- > Nige Danton - Replace the obvious with g.m.a.i.l You need to switch to the admin user. Sudo will only accept your own password, and only if you're in the "sudoers" file. If you don't want to log out, you can use the "su admin" command to change to admin within that shell- that one is expecting your admin password. Then as the admin, do the sudo python setup.py install and enter your admin password again. The point in all this is that your admin isn't actually an admin. There is only one account on the computer that actually has access to the core system files and that's "root". "sudo" is a command that lets you execute a command as another user by entering your own password. If you don't specify a user, it defaults to using root. An "admin" account on a Unix system is just an account with permission to use the sudo command. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.2 for Windows reports version as 2.7.0?
On Fri, Jun 17, 2011 at 5:55 PM, wrote: > Just installed the 32-bit version Python 2.7.2 for Windows via the > python-2.7.2.msi download. > > When I start Python via python.exe or Idle, the version info is reported as > 2.7.0 vs. 2.7.2. > > Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on > win > 32 > Type "help", "copyright", "credits" or "license" for more information. import sys sys.version_info > sys.version_info(major=2, minor=7, micro=0, releaselevel='final', serial=0) > > Here's the info on python.exe > > 06/12/2011 03:09 PM 26,624 python.exe > 06/12/2011 03:06 PM 27,136 pythonw.exe > > Is this a bug or did I upgrade my version of Python 2.7 wrong? > > Thank you, > Malcolm The file info is seems correct but I just checked the MSI and it's reporting that it's 2.7.2. How exactly are you running python.exe and IDLE- are you calling the full path, just calling "python" and using whichever python version is first on your path, or are you using an entry in the start menu? The only thing I can think of is that your 2.7.0 install is in a different location than your 2.7.2 install. So 2.7.2 installed correctly but you're still running the old one. -- http://mail.python.org/mailman/listinfo/python-list
Python 2.7.2 for Windows reports version as 2.7.0?
Just installed the 32-bit version Python 2.7.2 for Windows via the python-2.7.2.msi download. When I start Python via python.exe or Idle, the version info is reported as 2.7.0 vs. 2.7.2. Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.version_info sys.version_info(major=2, minor=7, micro=0, releaselevel='final', serial=0) >>> Here's the info on python.exe 06/12/2011 03:09 PM26,624 python.exe 06/12/2011 03:06 PM27,136 pythonw.exe Is this a bug or did I upgrade my version of Python 2.7 wrong? Thank you, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
In article I wrote, in part: >>Appending to the list is much faster, and if you are going to >>dump a set of new items in, you can do that with: [...] In article Ethan Furman wrote: >> a.append(large_list) > ^- should be a.extend(large_list) Er, right. Posted in haste (had to get out the door). I also wrote: >> If len(large_list) is m, this is O(m). Inserting each item in >> the "right place" would be O(m log (n + m)). But we still >> have to sort: >> >> a.sort() In article , Ian Kelly wrote: >> This is O(log (n + m)), hence likely better than repeatedly inserting >> in the correct place. >Surely you mean O((n + m) log (n + m)). Er, "maybe"? (It depends on the relative values of m and n, and the underlying sort algorithm to some extent. Some algorithms are better at inserting a relatively small number of items into a mostly-sorted large list. As I recall, Shell sort does well with this.) But generally, yes. See "posted in haste" above. :-) There are a lot of other options, such as sorting just the list of "items to be inserted", which lets you do a single merge pass: # UNTESTED def merge_sorted(it1, it2, must_copy = True): """ Merge two sorted lists/iterators it1 and it2. Roughly equivalent to sorted(list(it2) + list(it2)), except for attempts to be space-efficient. You can provide must_copy = False if the two iterators are already lists and can be destroyed for the purpose of creating the result. """ # If it1 and it1 are deque objects, we don't need to # reverse them, as popping from the front is efficient. # If they are plain lists, popping from the end is # required. If they are iterators or tuples we need # to make a list version anyway. So: if must_copy: it1 = list(it1) it2 = list(it2) # Reverse sorted lists (it1 and it2 are definitely # lists now) so that we can pop off the end. it1.reverse() it2.reverse() # Now accumulate final sorted list. Basically, this is: # take first (now last) item from each list, and put whichever # one is smaller into the result. When either list runs # out, tack on the entire remaining list (whichever one is # non-empty -- if both are empty, the two extend ops are # no-ops, so we can just add both lists). # # Note that we have to re-reverse them to get # them back into forward order before extending. result = [] while it1 and it2: # Note: I don't know if it might be faster # to .pop() each item and .append() the one we # did not want to pop after all. This is just # an example, after all. last1 = it1[-1] last2 = it2[-1] if last2 < last1: result.append(last2) it2.pop() else: result.append(last1) it1.pop() it1.reverse() it2.reverse() result.extend(it1) result.extend(it2) return result So, now if "a" is the original (sorted) list and "b" is the not-yet- sorted list of things to add: a = merge_sorted(a, sorted(b), must_copy = False) will work, provided you are not required to do the merge "in place". Use the usual slicing trick if that is necessary: a[:] = merge_sorted(a, sorted(b), must_copy = False) If list b is already sorted, leave out the sorted() step. If list b is not sorted and is particularly long, use b.sort() to sort in place, rather than making a sorted copy. -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Fun and games with lambda
On Sat, Jun 18, 2011 at 2:10 AM, Steven D'Aprano wrote: > If you've ever wondered what lambda and reduce are good for, run this one- > liner and wonder no more... > > (Be patient, it may take a few seconds to return.) I have a decent CPU so it's not too bad. And the precision produced is noteworthy. However, I have no idea how it does its work, so I'm just in awe of the quality of the code. And you can read that last remark either way. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyGUI 2.5
Terry Reedy wrote in news:mailman.88.1308338170.1164.python-l...@python.org: > On 6/16/2011 11:18 PM, Greg Ewing wrote: >> PyGUI 2.5 is available: >> >> http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ >> >> Lots of new stuff in this version. Highlights include: > > Greg left out the most important to me: > "Now works with Python 3 on MacOSX and Windows!" > Apparently *only* Python 3 ? C:\extracted\PyGUI-2.5>setup install Traceback (most recent call last): File "C:\extracted\PyGUI-2.5\setup.py", line 12, in from distutils_extensions import pygui_build_py ImportError: No module named distutils_extensions -- rzed -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
On Fri, Jun 17, 2011 at 3:48 PM, Chris Torek wrote: > If len(large_list) is m, this is O(m). Inserting each item in > the "right place" would be O(m log (n + m)). But we still > have to sort: > > a.sort() > > This is O(log (n + m)), hence likely better than repeatedly inserting > in the correct place. Surely you mean O((n + m) log (n + m)). -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
On Jun 17, 5:15 pm, Ethan Furman wrote: > John Salerno wrote: > > On Jun 17, 2:23 pm, Terry Reedy wrote: > > >> If you follow the second part of Greg's suggestion 'or one of the other > >> related function in the shutil module', you will find copytree() > >> "Recursively copy an entire directory tree rooted at src. " > > > Yeah, but shutil.copytree says: > > > "The destination directory, named by dst, must not already exist" > > > which again brings me back to the original problem. All I'm looking > > for is a simple way to copy files from one location to another, > > overwriting as necessary, but there doesn't seem to be a single > > function that does just that. > > If you don't mind deleting what's already there: > > shutil.rmtree(...) > shutil.copytree(...) > > If you do mind, roll your own (or borrow ;): > > 8<--- > #stripped down and modified version from 2.7 shutil (not tested) > def copytree(src, dst): > names = os.listdir(src) > if not os.path.exists(dst): # no error if already exists > os.makedirs(dst) > errors = [] > for name in names: > srcname = os.path.join(src, name) > dstname = os.path.join(dst, name) > try: > if os.path.isdir(srcname): > copytree(srcname, dstname, symlinks, ignore) > else: > copy2(srcname, dstname) > except (IOError, os.error), why: > errors.append((srcname, dstname, str(why))) > # catch the Error from the recursive copytree so that we can > # continue with other files > except Error, err: > errors.extend(err.args[0]) > if errors: > raise Error(errors) > 8<--- > > ~Ethan~ Thanks. Deleting what is already there is not a problem, I was just hoping to have it overwritten without any extra steps, but that's no big deal. -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing python27.dll on Win 7 64-bit
At 02:13 AM 6/17/2011, David Aldrich wrote: Hi I am building a 32-bit C++ application using Visual C++ Express 2008 on 64-bit Windows 7. The application links to Python, so I installed 32-bit Python 2.7.2 by running python-2.7.2.msi. When I run my app, I get error: ... python27.dll is missing from your computer ... and, indeed, it is in neither C:\Windows\System32 nor C:\Windows\SysWOW64. Please will someone suggest what I am doing wrong? Maybe nothing, maybe something, too little information to know. First, _look_ for the file. That is, find the file wherever it is. Go to the command line and do dir /s \ >allfiles.20110617a Then look at that listing. WIth Python 2.7.2 which I just installed the dll ends up in SysWOW64. And now I see that they are all there, and nowhere else! Directory of C:\Windows\SysWOW64 08/24/2010 07:47 PM 2,148,864 python26.dll 06/12/2011 03:09 PM 2,206,720 python27.dll 03/21/2010 01:43 AM 2,137,600 python31.dll 02/20/2011 10:29 PM 2,227,712 python32.dll But in December they were in both places! 2010/11/23 21:42:42 2148864 /cygdrive/c/Windows/System32/python26.dll 2010/11/23 21:45:32 2286080 /cygdrive/c/Windows/System32/python27.dll 2010/11/16 20:16:31 2137600 /cygdrive/c/Windows/System32/python31.dll 2010/11/23 21:42:42 2148864 /cygdrive/c/Windows/SysWOW64/python26.dll 2010/11/23 21:45:32 2286080 /cygdrive/c/Windows/SysWOW64/python27.dll 2010/11/16 20:16:31 2137600 /cygdrive/c/Windows/SysWOW64/python31.dll (Maybe something to do with the 32-bit vs. 64-bit installs mis-direction? I use only the 32-bit now...) Now, do another install of Python 2.7.2 on another machine. Do a file listing. Where do the DLLs end up? Re-do the install on your machine. Where do the DLLs end up? Do some more checking and tell us what you've _found_ and where... Best regards David -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
Chris Torek wrote: Appending to the list is much faster, and if you are going to dump a set of new items in, you can do that with: # wrong way: # for item in large_list: #a.append(item) # right way, but fundamentally still the same cost (constant # factor is much smaller due to built-in append()) a.append(large_list) ^- should be a.extend(large_list) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Jun 17, 2:26 pm, Dotan Cohen wrote: > On Fri, Jun 17, 2011 at 20:43, Xah Lee wrote: > > u r aware that there are already tens of layouts, each created by > > programer, thinking that they can create the best layout? > > Yes. Mine is better :) > Had Stallman not heard of VI when he set out to write Emacs? > > > > > > > if not, check > > 〈Computer Keyboards, Layouts, Hotkeys, Macros, RSI ⌨〉 > > xahlee.org/Periodic_dosage_dir/keyboarding.html > > > on layout section. Lots people all creating layouts. > > > also, you want to put {Enter, Tab}, etc keys in the middle, but I > > don't understand from ur website how u gonna do that since it requires > > keyboard hardware modification. e.g. r u creating key layout on PC > > keyboard or are you creating hardware keyboard Key layout? The former > > is a dime a million, the latter is rare but also there are several > > sites all trying to do it. Talk is cheap, the hardest part is actually > > to get money to finance and manufacture it. The latest one, which i > > deem good, is Truely Ergonomic keyboard. It sells for $200 and is in > > pre-order only now. > > I ordered the Truley Ergonomic keyboard, I waited for half a year > after delivery was supposed to happen to request my money back. Too > many delays, so in the end I bought a Ducky mechanical (Cherry Browns) > instead. > > I am writing a software keyboard layout. I'm actually having a hard > time moving the modifier keys (Alt, Ctrl) to a new location. If you > know how to do that I would much appreciate some advice, I'll post the > problem here or in private mail. > > Thanks, Lee. (or should that be Thanks, Xah?) thanks. didn't know about Ducky keyboard. Looks good. Also nice to hear your experience about Truly Ergonomic keyboard. no actually i don't know how to make normal letter keys as (ctrl, alt) modifiers. You'll need a usb hid remapper. (there's a couple for mac os x i linked on my site but i couldn't verify cuz am now on a 6 years old powerpc with outdated mac os x) For Windows, Microsoft made a layout maker. I haven't used it so i don't know if it allows mapping letter keys as modifier. Have you tried it? i don't know much about the subject but from what i read am guessing it's possible, because each key just send up/down signals. (whether you are using usb or ps/2 makes a difference too.) (am assumbing above that you want to put modifiers in normal letter key positions. But if all you want to do is swap modifier among themselves, that's pretty easy. Lots of tools to do that for mac and windows.) But even if you succeded in putting modifiers to letter key positions, you may run into problems with key ghosting, because the circuits are desigend to prevent ghosting on qwerty layout only (with mod keys in their normal positions). Unless your keyboard is actually full n-key- roll-over. maybe some of these are useful info, but maybe you are quite beyond that. Thanks for your info too. Good luck. just Xah -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
John Salerno wrote: On Jun 17, 2:23 pm, Terry Reedy wrote: If you follow the second part of Greg's suggestion 'or one of the other related function in the shutil module', you will find copytree() "Recursively copy an entire directory tree rooted at src. " Yeah, but shutil.copytree says: "The destination directory, named by dst, must not already exist" which again brings me back to the original problem. All I'm looking for is a simple way to copy files from one location to another, overwriting as necessary, but there doesn't seem to be a single function that does just that. If you don't mind deleting what's already there: shutil.rmtree(...) shutil.copytree(...) If you do mind, roll your own (or borrow ;): 8<--- #stripped down and modified version from 2.7 shutil (not tested) def copytree(src, dst): names = os.listdir(src) if not os.path.exists(dst): # no error if already exists os.makedirs(dst) errors = [] for name in names: srcname = os.path.join(src, name) dstname = os.path.join(dst, name) try: if os.path.isdir(srcname): copytree(srcname, dstname, symlinks, ignore) else: copy2(srcname, dstname) except (IOError, os.error), why: errors.append((srcname, dstname, str(why))) # catch the Error from the recursive copytree so that we can # continue with other files except Error, err: errors.extend(err.args[0]) if errors: raise Error(errors) 8<--- ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
In article SherjilOzair wrote: >There are basically two ways to go about this. >One is, to append the new value, and then sort the list. >Another is to traverse the list, and insert the new value at the >appropriate position. > >The second one's complexity is O(N), while the first one's is O(N * >log N). This is not quite right; see below. >Still, the second one works much better, because C code is being used >instead of pythons. > >Still, being a programmer, using the first way (a.insert(x); >a.sort()), does not feel right. > >What has the community to say about this ? What is the best (fastest) >way to insert sorted in a list ? In this case, the "best" way is most likely "don't do that at all". First, we should note that a python list() data structure is actually an array. Thus, you can locate the correct insertion point pretty fast, by using a binary or (better but not as generally applicable) interpolative search to find the proper insertion point. Having found that point, though, there is still the expense of the insertion, which requires making some room in the array-that- makes-the-list (I will use the name "a" as you did above): position = locate_place_for_insert(a, the_item) # The above is O(log n) for binary search, # O(log log n) for interpolative search, where # n is len(a). a.insert(position, the_item) # This is still O(log n), alas. Appending to the list is much faster, and if you are going to dump a set of new items in, you can do that with: # wrong way: # for item in large_list: #a.append(item) # right way, but fundamentally still the same cost (constant # factor is much smaller due to built-in append()) a.append(large_list) If len(large_list) is m, this is O(m). Inserting each item in the "right place" would be O(m log (n + m)). But we still have to sort: a.sort() This is O(log (n + m)), hence likely better than repeatedly inserting in the correct place. Depending on your data and other needs, though, it might be best to use a red-black tree, an AVL tree, or a skip list. You might also investigate radix sort, radix trees, and ternary search trees (again depending on your data). -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: installing NLTK
On 17/06/11 22:57:41, Nige Danton wrote: Hans Mulder wrote: On 17/06/11 21:58:53, Nige Danton wrote: Mac OSX python 2.6.1: I'm trying to install the natural language toolkit and following the instructions here www.NLTK.org/download I've downloaded the PyYAML package and in a terminal window tried to install it. However You're not really giving us enough information, so I'll just guess: Sorry. Are you trying a command that begins with "sudo"? Good guess. Yes it's sudo python setup.py install If so, then you user password should work, provided you're a member of the 'admin' group. To find out, type "groups" in a Terminal window. If the response does not include "admin" as a separate Ok, thanks. Tried that and the response does not include admin nor my user name word, then you''l have to ask someone to give you admin rights. It's a personal computer - there is no one to ask. When I try my user password the reply is that it's not in the sudoers file and the admin password it just rejects. Any idea what I should do? If you open the "System Preferences" application, and click "Accounts" (the icon in the lower left), do you get to see your own account? If so, is the checkbox "Allow user to administer this computer" checked? If not, try logging out, log in as "admin" and go back to "Accounts" in "System Preferences". If the lock in the lower left corner is in the "locked" state, click it and give the password to open it. Then select your own account, check the checkbox, log out and log back in as yourself. That should make you a member of the "admin" group. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
On Jun 17, 2:23 pm, Terry Reedy wrote: > If you follow the second part of Greg's suggestion 'or one of the other > related function in the shutil module', you will find copytree() > "Recursively copy an entire directory tree rooted at src. " Yeah, but shutil.copytree says: "The destination directory, named by dst, must not already exist" which again brings me back to the original problem. All I'm looking for is a simple way to copy files from one location to another, overwriting as necessary, but there doesn't seem to be a single function that does just that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Fri, Jun 17, 2011 at 20:43, Xah Lee wrote: > u r aware that there are already tens of layouts, each created by > programer, thinking that they can create the best layout? > Yes. Mine is better :) Had Stallman not heard of VI when he set out to write Emacs? > if not, check > 〈Computer Keyboards, Layouts, Hotkeys, Macros, RSI ⌨〉 > xahlee.org/Periodic_dosage_dir/keyboarding.html > > on layout section. Lots people all creating layouts. > > also, you want to put {Enter, Tab}, etc keys in the middle, but I > don't understand from ur website how u gonna do that since it requires > keyboard hardware modification. e.g. r u creating key layout on PC > keyboard or are you creating hardware keyboard Key layout? The former > is a dime a million, the latter is rare but also there are several > sites all trying to do it. Talk is cheap, the hardest part is actually > to get money to finance and manufacture it. The latest one, which i > deem good, is Truely Ergonomic keyboard. It sells for $200 and is in > pre-order only now. > I ordered the Truley Ergonomic keyboard, I waited for half a year after delivery was supposed to happen to request my money back. Too many delays, so in the end I bought a Ducky mechanical (Cherry Browns) instead. I am writing a software keyboard layout. I'm actually having a hard time moving the modifier keys (Alt, Ctrl) to a new location. If you know how to do that I would much appreciate some advice, I'll post the problem here or in private mail. Thanks, Lee. (or should that be Thanks, Xah?) -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
On Fri, Jun 17, 2011 at 3:02 PM, Shashank Singh wrote: > Correct me if I am wrong here but isn't the second one is O(log N)? > Binary search? > That is when you have an already sorted list from somewhere and you > are inserting just one new value. Finding the position to insert is O(log n), but the actual insert is O(n). This is because Python lists are implemented with arrays and everything after the inserted item has to be moved in memory to make space for the insert. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
SherjilOzair wrote: What has the community to say about this ? What is the best (fastest) way to insert sorted in a list ? Check out the bisect module. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
On Sat, Jun 18, 2011 at 2:23 AM, SherjilOzair wrote: > There are basically two ways to go about this. > One is, to append the new value, and then sort the list. > Another is to traverse the list, and insert the new value at the > appropriate position. > > The second one's complexity is O(N), while the first one's is O(N * > log N). Correct me if I am wrong here but isn't the second one is O(log N)? Binary search? That is when you have an already sorted list from somewhere and you are inserting just one new value. In case you are building the whole list yourself it's the same (N * log N) > > Still, the second one works much better, because C code is being used > instead of pythons. > > Still, being a programmer, using the first way (a.insert(x); > a.sort()), does not feel right. > > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards Shashank Singh http://www.cse.iitb.ac.in/~shashanksingh -- http://mail.python.org/mailman/listinfo/python-list
Re: installing NLTK
Hans Mulder wrote: > On 17/06/11 21:58:53, Nige Danton wrote: >> Mac OSX python 2.6.1: I'm trying to install the natural language toolkit >> and following the instructions here www.NLTK.org/download I've downloaded >> the PyYAML package and in a terminal window tried to install it. However > You're not really giving us enough information, so I'll just guess: Sorry. > Are you trying a command that begins with "sudo"? Good guess. Yes it's sudo python setup.py install > If so, then you user password should work, provided you're a member > of the 'admin' group. To find out, type "groups" in a Terminal > window. If the response does not include "admin" as a separate Ok, thanks. Tried that and the response does not include admin nor my user name > word, then you''l have to ask someone to give you admin rights. It's a personal computer - there is no one to ask. When I try my user password the reply is that it's not in the sudoers file and the admin password it just rejects. Any idea what I should do? -- Nige Danton - Replace the obvious with g.m.a.i.l -- http://mail.python.org/mailman/listinfo/python-list
Best way to insert sorted in a list
There are basically two ways to go about this. One is, to append the new value, and then sort the list. Another is to traverse the list, and insert the new value at the appropriate position. The second one's complexity is O(N), while the first one's is O(N * log N). Still, the second one works much better, because C code is being used instead of pythons. Still, being a programmer, using the first way (a.insert(x); a.sort()), does not feel right. What has the community to say about this ? What is the best (fastest) way to insert sorted in a list ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in a shell script
On Fri, 17 Jun 2011 22:15:57 +0200, Hans Mulder said: > On 17/06/11 19:47:50, Timo Lindemann wrote: >> On Fri, 17 Jun 2011 00:57:25 +, Jason Friedman said: >> >> >> >>> but for various reasons I want a single script. Any alternatives? >> >> you can use a here document like this: > That does not solve the problem as stated. The OP wants to call python > inside a loop and he wants to indent things properly: so, wrap it inside a bash function like this: #! /bin/bash call_python() { /usr/bin/python2 << EOPYTHON def hello(): print("Hello, World $1"); if __name__ == "__main__": hello(); EOPYTHON } for i in 1 2 3 4 5 6 do call_python $i done That way, the indentation on is nicer; passing parameters to the script inside the heredoc might be mean if the parameters are formed difficultly, like, causing syntax errors if it's something like '"' or somesuch. Probably beside the point though. > For some ideas that may work, read the earlier posts in this thread. maybe my news server doesn't fetch the whole thread. I didnt see any replies, and still don't except yours. Nice evenin' -T. -- http://mail.python.org/mailman/listinfo/python-list
Re: installing NLTK
On 17/06/11 21:58:53, Nige Danton wrote: Mac OSX python 2.6.1: I'm trying to install the natural language toolkit and following the instructions here www.NLTK.org/download I've downloaded the PyYAML package and in a terminal window tried to install it. However terminal asks for my password - I've tried both my user password and admin password but neither is accepted. What am I doing wrong? You're not really giving us enough information, so I'll just guess: Are you trying a command that begins with "sudo"? If so, then you user password should work, provided you're a member of the 'admin' group. To find out, type "groups" in a Terminal window. If the response does not include "admin" as a separate word, then you''l have to ask someone to give you admin rights. Otherwise, you'll have to tell us what command you are trying. We're too lazy to download the PyYAML package, just to read the installation instructions. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in a shell script
On 17/06/11 19:47:50, Timo Lindemann wrote: On Fri, 17 Jun 2011 00:57:25 +, Jason Friedman said: but for various reasons I want a single script. Any alternatives? you can use a here document like this: #! /bin/bash /usr/bin/python2<< EOPYTHON def hello(): print("Hello, World"); if __name__ == "__main__": hello(); EOPYTHON That does not solve the problem as stated. The OP wants to call python inside a loop and he wants to indent things properly: #!/bin/bash for i in 1 2 3 4 5 do python << EOPYTHON def hello(): print("Hello, World"); if __name__ == "__main__": hello(); EOPYTHON done That doesn't work, because the EOPYTHON token is indented. If you put the EOPYTHON token flush left, it still doesn't work, because Python does not accept indentation on line 1: File "", line 1 def hello(): ^ IndentationError: unexpected indent For some ideas that may work, read the earlier posts in this thread. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
installing NLTK
Mac OSX python 2.6.1: I'm trying to install the natural language toolkit and following the instructions here www.NLTK.org/download I've downloaded the PyYAML package and in a terminal window tried to install it. However terminal asks for my password - I've tried both my user password and admin password but neither is accepted. What am I doing wrong? Thanks for any help -- Nige Danton - Replace the obvious with g.m.a.i.l -- http://mail.python.org/mailman/listinfo/python-list
Re: bug in large file writes, 2.x and 3.x
MRAB wrote: On 17/06/2011 20:15, Ethan Furman wrote: Ethan Furman wrote: Windows platform (XP Pro, SP2). This works fine on local drives, but on network (both 2003 Server, and Samba running on FreeBSD) the following produces an error: --> data = '?' * 119757831 # use b'?' if on 3.x --> test = open(r's:\junk.tst', 'wb') --> test.write(data) Traceback (most recent call last): File "", line 1, in IOError: [Errno 22] Invalid argument Update: 10Mb worth of data succeeds, 50+Mb fails. What about around 2**24 bytes? 8<-- def test_network_write_failure(): size = 100 * 1024 * 1024 half = size // 2 while 'Here we go!': print('trying', size) data = b'?' * size test = open(r's:\test.jnk', 'wb') try: test.write(data) except IOError: test.close() else: size = size + half half = half // 2 continue test = open(r's:\test.jnk', 'wb') try: test.write(data[:-1]) except IOError: test.close() size = size - half half = half // 2 continue print("%d succeeded, %d failed" % (size-1, size)) break if __name__ == '__main__': test_network_write_failure() 8<-- On my machine I get: c:\temp>\python32\python nwf.py trying 104857600 trying 52428800 trying 26214400 trying 39321600 trying 45875200 trying 49152000 trying 50790400 trying 51609600 trying 5120 trying 50995200 trying 50892800 trying 50841600 trying 50867200 trying 5088 trying 50873600 trying 50870400 trying 50868800 trying 50868000 trying 50868400 trying 50868200 trying 50868100 trying 50868150 trying 50868175 trying 50868187 trying 50868181 trying 50868178 trying 50868177 50868176 succeeded, 50868177 failed ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyGUI 2.5
> Lots of new stuff in this version. Highlights include: >- GridView - a user-defined view consisting of a regular grid of > cells. > >- PaletteView - a GridView specialised for implementing tool > palettes. Any chance to see a hierarchical multi-column TreeListView anytime soon? Sincerely, Wolfgang -- Führungskräfte leisten keine Arbeit(D'Alembert) -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
On 6/17/2011 12:17 PM, John Salerno wrote: On Jun 17, 2:25 am, Gregory Ewing wrote: It sounds like shutil.copy() is what you want, or one of the other related functions in the shutil module. This looks promising! But can src be a directory, or does it have to be a file? For my purposes (copying a saved games folder), I don't really need to specify particular files to copy, I just need to copy the entire Saved Games directory, so that's what would be my src argument if allowed. If you follow the second part of Greg's suggestion 'or one of the other related function in the shutil module', you will find copytree() "Recursively copy an entire directory tree rooted at src. " Also, the directory I want to copy also contains a directory. Will the contents of that directory also be copied, or do I have to do some kind of walk-through of the directory manually? If you want more control of which files to copy, between 1 and all, look as os.walk and the glob module. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyGUI 2.5
On 6/16/2011 11:18 PM, Greg Ewing wrote: PyGUI 2.5 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Lots of new stuff in this version. Highlights include: Greg left out the most important to me: "Now works with Python 3 on MacOSX and Windows!" -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: bug in large file writes, 2.x and 3.x
On 17/06/2011 20:15, Ethan Furman wrote: Ethan Furman wrote: Windows platform (XP Pro, SP2). This works fine on local drives, but on network (both 2003 Server, and Samba running on FreeBSD) the following produces an error: --> data = '?' * 119757831 # use b'?' if on 3.x --> test = open(r's:\junk.tst', 'wb') --> test.write(data) Traceback (most recent call last): File "", line 1, in IOError: [Errno 22] Invalid argument Update: 10Mb worth of data succeeds, 50+Mb fails. What about around 2**24 bytes? -- http://mail.python.org/mailman/listinfo/python-list
Re: Fun and games with lambda
On Jun 17, 5:10 pm, Steven D'Aprano wrote: > > print((lambda f:((lambda p:p[0]+'.'+p[1:])(str((lambda Q:2*Q[0]*Q[0]//Q > [3])((lambda F:(lambda S:f(lambda T,_:((T[0]+T[1])//2,S((T[0]*T[1])// > F),2*T[2],(T[3]-(T[2]*(((T[0]+T[1])//2)**2-(S((T[0]*T[1])//F))**2))//F)), > [0]*13,(F,(F*F)//S(2*F),2,F//2)))(lambda n:f(lambda x,_:(x-x//2+(n*F)// > (2*x)),[0]*15,n//2)))(10**(5010[:5000])))(reduce)) Very nice, but a little unnatural. Can't you find room to stick an extra factor of 2 in there somewhere? (See also: http://bugs.python.org/issue12345 ) -- Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: bug in large file writes, 2.x and 3.x
On 6/17/2011 3:03 PM, Ethan Furman wrote: Windows platform (XP Pro, SP2). This works fine on local drives, but on network (both 2003 Server, and Samba running on FreeBSD) the following produces an error: --> data = '?' * 119757831 # use b'?' if on 3.x --> test = open(r's:\junk.tst', 'wb') --> test.write(data) Traceback (most recent call last): File "", line 1, in IOError: [Errno 22] Invalid argument Just curious, how big is 'large'? Rather, how bit to get an error? Any ideas on whether this is Python or MS Windows? (Personally, I'm betting on Windows). Python should not know the difference betweeen 'c:xxx' and 's:xxx'. The error comes from Windoes. But 100 million bytes does not seem really large for today's systems. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: bug in large file writes, 2.x and 3.x
Ethan Furman wrote: Windows platform (XP Pro, SP2). This works fine on local drives, but on network (both 2003 Server, and Samba running on FreeBSD) the following produces an error: --> data = '?' * 119757831 # use b'?' if on 3.x --> test = open(r's:\junk.tst', 'wb') --> test.write(data) Traceback (most recent call last): File "", line 1, in IOError: [Errno 22] Invalid argument Update: 10Mb worth of data succeeds, 50+Mb fails. -- http://mail.python.org/mailman/listinfo/python-list
bug in large file writes, 2.x and 3.x
Windows platform (XP Pro, SP2). This works fine on local drives, but on network (both 2003 Server, and Samba running on FreeBSD) the following produces an error: --> data = '?' * 119757831 # use b'?' if on 3.x --> test = open(r's:\junk.tst', 'wb') --> test.write(data) Traceback (most recent call last): File "", line 1, in IOError: [Errno 22] Invalid argument Any ideas on whether this is Python or MS Windows? (Personally, I'm betting on Windows). ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Jun 15, 5:43 am, rusi wrote: > On Jun 15, 5:32 pm, Dotan Cohen wrote: > > > Thanks. From testing small movements with my fingers I see that the > > fourth finger is in fact a bit weaker than the last finger, but more > > importantly, it is much less dexterous. Good to know! > > Most of the piano technique-icians emphasis, especially those of the > last century like Hanon, was to cultivate 'independence' of the > fingers. The main target of these attacks being the 4th finger. > > The number of potential-pianists who ruined their hands and lives > chasing this holy grail is unknown Hi rusi, am afaid going to contradict what u say here. i pretty much mastered Hanon 60. All of it, but it was now 8 years ago. The idea that pinky is stronger than 4th is silly. I can't fathom any logic or science to support that. Perhaps what u meant is that in many situations the use of pinky can be worked around because it in at the edge of your hand so you can apply chopping motion or similar. (which, is BAD if you want to develope piano finger skill) However, that's entirely different than saying pinky being stronger than 4th. there's many ways we can cookup tests right away to see. e.g. try to squeeze a rubber ball with 4th and thumb. Repeat with pink + thumb. Or, reverse exercise by stretching a rubber band wrapped on the 2 fingers of interest. You can easy see that pinky isn't stronger. Xah -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTPConncetion - HEAD request
On 17 Giu, 12:14, Adam Tauno Williams wrote: > On Thu, 2011-06-16 at 15:43 -0700, gervaz wrote: > > Hi all, can someone tell me why the read() function in the following > > py3 code returns b'' > > >>> h = http.client.HTTPConnection("www.twitter.com") > > >>> h.connect() > > >>> h.request("HEAD", "/", "HTTP 1.0") > > >>> r = h.getresponse() > > >>> r.read() > > b'' > > Because there is no body in a HEAD request. What is useful are the > Content-Type, Content-Length, and etag headers. > > Is r.getcode() == 200? That indicates a successful response; you > *always* much check the response code before interpreting the response. > > Also I'm pretty sure that "HTTP 1.0" is wrong. Ok, thanks for the replies, just another question in order to have a similar behaviour using a different approach... I decided to implement this solution: class HeadRequest(urllib.request.Request): def get_method(self): return "HEAD" Now I download the url using: r = HeadRequest(url, None, self.headers) c = urllib.request.urlopen(r) but I don't know how to retrieve the request status (e.g. 200) as in the previous examples with a different implementation... Any suggestion? Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in a shell script
On Fri, 17 Jun 2011 00:57:25 +, Jason Friedman said: > > but for various reasons I want a single script. Any alternatives? you can use a here document like this: #! /bin/bash /usr/bin/python2 << EOPYTHON def hello(): print("Hello, World"); if __name__ == "__main__": hello(); EOPYTHON -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Jun 14, 7:50 am, Dotan Cohen wrote: > On Mon, Jun 13, 2011 at 10:21, Elena wrote: > > On 13 Giu, 06:30, Tim Roberts wrote: > >> Studies have shown that even a > >> strictly alphabetical layout works perfectly well, once the typist is > >> acclimated. > > > Once the user is acclimated to move her hands much more (about 40% > > more for Qwerty versus Dvorak), that is. > > And disproportionate usage of fingers. On QWERTY the weakest fingers > (pinkies) do almost 1/4 of the keypresses when modifier keys, enter, > tab, and backspace are taken into account. > > I'm developing a QWERTY-based layout that moves the load off the > pinkies and onto the index > fingers:http://dotancohen.com/eng/noah_ergonomic_keyboard_layout.html > > There is a Colemak version in the works as well. u r aware that there are already tens of layouts, each created by programer, thinking that they can create the best layout? if not, check 〈Computer Keyboards, Layouts, Hotkeys, Macros, RSI ⌨〉 xahlee.org/Periodic_dosage_dir/keyboarding.html on layout section. Lots people all creating layouts. also, you want to put {Enter, Tab}, etc keys in the middle, but I don't understand from ur website how u gonna do that since it requires keyboard hardware modification. e.g. r u creating key layout on PC keyboard or are you creating hardware keyboard Key layout? The former is a dime a million, the latter is rare but also there are several sites all trying to do it. Talk is cheap, the hardest part is actually to get money to finance and manufacture it. The latest one, which i deem good, is Truely Ergonomic keyboard. It sells for $200 and is in pre-order only now. Xah -- http://mail.python.org/mailman/listinfo/python-list
import from environment path
Hi, Here's my situation : I got a script a.py that need to call b.py. The 2 scripts can't be in a same package. Script a.py knows the path of b.py relative to an environment variable B_PATH, let's say B_PATH/foo/ b.py. The solution I found is to do the flowwing : b_dir = os.path.join(os.environ['B_PATH'], 'foo') sys.path.append(b_dir) import b b.main() Is it the right way to do it, should I use subprocess.call instead? -- http://mail.python.org/mailman/listinfo/python-list
Re: Fun and games with lambda
On Fri, Jun 17, 2011 at 10:56 AM, Wolfgang Rohdewald wrote: > On Freitag 17 Juni 2011, Steven D'Aprano wrote: >> run this one- >> liner and wonder no more... > > looks like something dangerous to me. What does > it do? rm -rf ? The thread at the link discusses what it does in great detail. -- http://mail.python.org/mailman/listinfo/python-list
Re: Run Python script from JS
Hansmeet Singh wrote: > for xhtml wouldnt the syntax be
ANN: PyGUI 2.5
PyGUI 2.5 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Lots of new stuff in this version. Highlights include: - Improved facilities for customising the standard menus. - Functions for creating PyGUI Images from PIL images and numpy arrays. - ListButton - a pop-up or pull-down menu of choices. - GridView - a user-defined view consisting of a regular grid of cells. - PaletteView - a GridView specialised for implementing tool palettes. There is also a big pile of other improvements and bug fixes. See the CHANGES file for full details. 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: How to avoid "()" when writing a decorator accepting optional arguments?
Giampaolo Rodolà wrote: I've written this decorator to deprecate a function and (optionally) provide a callable as replacement I can see providing the replacement function so that you can say, for example, "you are calling a deprecated function -- is the replacement". If your replacement function is drop-in compatible, though, why bother with the whole deprecate decorator? Just drop it in! :) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Fun and games with lambda
On Freitag 17 Juni 2011, Steven D'Aprano wrote: > run this one- > liner and wonder no more... looks like something dangerous to me. What does it do? rm -rf ? -- Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
On 01/-10/-28163 02:59 PM, John Salerno wrote: Based on what I've read, it seems os.rename is the proper function to use, but I'm a little confused about the syntax. Basically I just want to write a simple script that will back up my saved game files when I run it. So I want it to copy a set of files/directories from a location on my C:\ drive to another directory on my E:\ drive. I don't want to rename or delete the originals, just move them. I also want them to automatically overwrite whatever already happens to be in the location on the E:\ drive. Is os.rename the proper function for this? Mainly I was because the Module Index says this: "On Windows, if dst already exists, OSError will be raised even if it is a file.." so it sounds like I can't move the files to a location where those file names already exist. You keep saying 'move' when you want 'copy.' Even if os.rename would work across drives (it doesn't, on Windows), it still would be removing the original. Similarly with move. As Greg mentioned, you want shutil.copy(), not move nor rename. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
On Jun 17, 2:25 am, Gregory Ewing wrote: > John Salerno wrote: > > I want it to copy a set of files/directories from a > > location on my C:\ drive to another directory on my E:\ drive. I don't > > want to rename or delete the originals, > > It sounds like shutil.copy() is what you want, or one of the > other related functions in the shutil module. > > -- > Greg shutil.copy(src, dst) Copy the file src to the file or directory dst. If dst is a directory, a file with the same basename as src is created (or overwritten) in the directory specified. Permission bits are copied. src and dst are path names given as strings. This looks promising! But can src be a directory, or does it have to be a file? For my purposes (copying a saved games folder), I don't really need to specify particular files to copy, I just need to copy the entire Saved Games directory, so that's what would be my src argument if allowed. Also, the directory I want to copy also contains a directory. Will the contents of that directory also be copied, or do I have to do some kind of walk-through of the directory manually? -- http://mail.python.org/mailman/listinfo/python-list
Fun and games with lambda
If you've ever wondered what lambda and reduce are good for, run this one- liner and wonder no more... (Be patient, it may take a few seconds to return.) # Python 2 version: print((lambda f:((lambda p:p[0]+'.'+p[1:])(str((lambda Q:2*Q[0]*Q[0]//Q [3])((lambda F:(lambda S:f(lambda T,_:((T[0]+T[1])//2,S((T[0]*T[1])// F),2*T[2],(T[3]-(T[2]*(((T[0]+T[1])//2)**2-(S((T[0]*T[1])//F))**2))//F)), [0]*13,(F,(F*F)//S(2*F),2,F//2)))(lambda n:f(lambda x,_:(x-x//2+(n*F)// (2*x)),[0]*15,n//2)))(10**(5010[:5000])))(reduce)) # Python 3 version: print((lambda f:((lambda p:p[0]+'.'+p[1:])(str((lambda Q:2*Q[0]*Q[0]//Q [3])((lambda F:(lambda S:f(lambda T,_:((T[0]+T[1])//2,S((T[0]*T[1])// F),2*T[2],(T[3]-(T[2]*(((T[0]+T[1])//2)**2-(S((T[0]*T[1])//F))**2))//F)), [0]*13,(F,(F*F)//S(2*F),2,F//2)))(lambda n:f(lambda x,_:(x-x//2+(n*F)// (2*x)),[0]*15,n//2)))(10**(5010[:5000])))(__import__ ('functools').reduce)) I can't take credit for this little beauty. It originally came from Manuel Garcia, all I did was make it compatible with Python 3 and add some additional, but trivial, obfuscation. See the original post here: http://web.archiveorange.com/archive/v/5H3d1yQN5N15HEgOWHMx Encouraging-hatred-of-lambdas-for-fun-and-profit-ly y'rs, -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: SQL Server 2008R2 databases via Python 2.7 and Windows XP and higher
On Jun 17, 2011, at 17:01, pyt...@bdurham.com wrote: > Looking for some real-world advice on what is the best way to access MS SQL > Server 2008R2 databases via Python 2.7 running under Windows XP, Vista, and > Windows 7 and Windows Server 2005 and 2008. I use the COM interface to ADO, for a few years already, but want to rewrite my scripts to the standard DBAPI 2.0 sometime to be less dependent on Windows. -- "Freedom: To ask nothing. To expect nothing. To depend on nothing." - Ayn Rand -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Lisp : car and cdr
On Fri, Jun 17, 2011 at 8:45 AM, Franck Ditter wrote: > Hi, I'm just wondering about the complexity of some Python operations > to mimic Lisp car and cdr in Python... > > def length(L) : > if not L : return 0 > return 1 + length(L[1:]) > > Should I think of the slice L[1:] as (cdr L) ? I mean, is the slice > a copy of a segment of L, or do I actually get a pointer to something > inside L ? The slice is a copy of a segment of L. > Is the above function length O(n) or probably O(n^2) ? O(n^2). If you want to implement Lisp-style list processing in Python, Python lists are not the most efficient data type to do it with. I would suggest using 2-element tuples to represent cons cells and building up from there. Also note that Python does not do tail recursion optimization, so recursion in general is inefficient and prone to stack overflow if the data structure is large enough. > Where are such implementation things (well) said ? http://docs.python.org/tutorial/introduction.html#lists -- http://mail.python.org/mailman/listinfo/python-list
Re: SQL Server 2008R2 databases via Python 2.7 and Windows XP and higher
pyt...@bdurham.com wrote: Looking for some real-world advice on what is the best way to access MS SQL Server 2008R2 databases via Python 2.7 running under Windows XP, Vista, and Windows 7 and Windows Server 2005 and 2008. Based on my research, here's my list of choices: mxODBC http://www.egenix.com/products/python/mxODBC/ pyOdbc 2.1.8 http://code.google.com/p/pyodbc pyMSSQL 1.02 http://code.google.com/p/pymssql My usage is extremely light, but pyodbc is working well for me. I have not tried the others, so they may also have these pyodbc features: name referencing in returned rows (not just indexing); and ability to change values in returned rows (local change only). ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: SQL Server 2008R2 databases via Python 2.7 and Windows XP and higher
On 17/06/2011 16:01, pyt...@bdurham.com wrote: Looking for some real-world advice on what is the best way to access MS SQL Server 2008R2 databases via Python 2.7 running under Windows XP, Vista, and Windows 7 and Windows Server 2005 and 2008. Based on my research, here's my list of choices: mxODBC http://www.egenix.com/products/python/mxODBC/ pyOdbc 2.1.8 http://code.google.com/p/pyodbc pyMSSQL 1.02 http://code.google.com/p/pymssql I use pyodbc (and have done for some years) without any problems at all. Barring the one or two issues I've logged which are being addressed. (grin). We use pretty much exactly the mixture of platforms you're describing. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: How to avoid "()" when writing a decorator accepting optional arguments?
On Jun 17, 3:53 pm, Ian Kelly wrote: > > That works, but I would be concerned about forgetting to specify the > argument by keyword (snip funny side effect description) > Also, as in my suggestion, it doesn't seem > like a big improvement to have to type out "replacement=" when you > need the replacement function just to avoid typing "()" when you > don't. I wholefully agree with you on both points. FWIW, it was just for the sake of being technically correct which, as everyone should know, is "the best kind of correct"), not about being practically helpful in anyway -- http://mail.python.org/mailman/listinfo/python-list
Reconstituting f2py Multi-dimensional character array
Hello all, I've normally only had to build a list of words from a f2py fortran character array. For this I found the transpose method to work fine. However I have had difficulty finding a way of getting a 3d array of words from Fortran to python. (I.e. 4d in python) I've attached 2 files that are my test-run. On windows I create the windummy.prd file by using the following command: python C:\Python26\Scripts\f2py.py -c -m windummy --fcompiler=gnu95 --compiler=mingw32 -lmsvcr90 --verbose dummy.f95 or in linux f2py -c -m lindummy --fcompiler=gnu95 --verbose dummy.f95 My problem is a bit "Morecambe & Wise" in that I can get all the 3-letter words, but not necessarily in the right order. I have tried various transpose methods to try and get things in order but with no luck. There's very little on the boards. Any help would be *MASSIVELY* appreciated. Many thanks in advance, HF dummy.f95 Description: Binary data dummy.py Description: Binary data -- http://mail.python.org/mailman/listinfo/python-list
SQL Server 2008R2 databases via Python 2.7 and Windows XP and higher
Looking for some real-world advice on what is the best way to access MS SQL Server 2008R2 databases via Python 2.7 running under Windows XP, Vista, and Windows 7 and Windows Server 2005 and 2008. Based on my research, here's my list of choices: mxODBC [1]http://www.egenix.com/products/python/mxODBC/ pyOdbc 2.1.8 [2]http://code.google.com/p/pyodbc pyMSSQL 1.02 [3]http://code.google.com/p/pymssql Any tips or advice appreciated. Thanks, Malcolm References 1. http://www.egenix.com/products/python/mxODBC/ 2. http://code.google.com/p/pyodbc 3. http://code.google.com/p/pymssql -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing python27.dll on Win 7 64-bit
I don't have Windows at hand, by I *guess* that the Python DLL is somewhere near the python executable. You need to make sure the Python DLL is in PATH, either copy it next to your executable or edit the PATH environment variable. -- http://mail.python.org/mailman/listinfo/python-list
Python and Lisp : car and cdr
Hi, I'm just wondering about the complexity of some Python operations to mimic Lisp car and cdr in Python... def length(L) : if not L : return 0 return 1 + length(L[1:]) Should I think of the slice L[1:] as (cdr L) ? I mean, is the slice a copy of a segment of L, or do I actually get a pointer to something inside L ? Is the above function length O(n) or probably O(n^2) ? Where are such implementation things (well) said ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: How to avoid "()" when writing a decorator accepting optional arguments?
On Fri, Jun 17, 2011 at 4:27 AM, bruno.desthuilli...@gmail.com wrote: > On Jun 11, 10:28 pm, Ian Kelly wrote: >> >> Since there is no way to distinguish the two cases by the arguments, > > def deprecated(func=None, replacement=None): > if replacement: > # handle the case where a replacement has been given > elif func: > # handle the case where no replacement has been given > else: > raise ValueErrorOrSomethingLikeThis() > > > @deprecated(replacement=other_func): > def some_func(args): > # code here > > @deprecated > def another_func(args): > # code here That works, but I would be concerned about forgetting to specify the argument by keyword, which would have the effect of deprecating the replacement function and then calling it on the function that was intended to be deprecated. Also, as in my suggestion, it doesn't seem like a big improvement to have to type out "replacement=" when you need the replacement function just to avoid typing "()" when you don't. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: integer to binary 0-padded
On Jun 15, 9:33 am, Olivier LEMAIRE wrote: > You're right, I use Python 2.6.6 This works great in 2.6.5 and later (and probably earlier). You just have to number your placeholders. The first set of braces formats i (your value), the second set specifies the field with (i.e., 8): >>> for i in xrange(10): ... print "{0:0{1}b}".format(i,8) ... 0001 0010 0011 0100 0101 0110 0111 1000 1001 -- http://mail.python.org/mailman/listinfo/python-list
Re: Composing regex from a list
Steven D'Aprano wrote: > def compile_alternatives(*args): Thank you all, for these good points. For my eyes seem that explicit or implicit it will take some looping to concatenate the list elements into a string. I will see pypy later. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How to avoid "()" when writing a decorator accepting optional arguments?
On Jun 11, 10:28 pm, Ian Kelly wrote: > > Since there is no way to distinguish the two cases by the arguments, def deprecated(func=None, replacement=None): if replacement: # handle the case where a replacement has been given elif func: # handle the case where no replacement has been given else: raise ValueErrorOrSomethingLikeThis() @deprecated(replacement=other_func): def some_func(args): # code here @deprecated def another_func(args): # code here My 2 cents... -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTPConncetion - HEAD request
On Thu, 2011-06-16 at 15:43 -0700, gervaz wrote: > Hi all, can someone tell me why the read() function in the following > py3 code returns b'' > >>> h = http.client.HTTPConnection("www.twitter.com") > >>> h.connect() > >>> h.request("HEAD", "/", "HTTP 1.0") > >>> r = h.getresponse() > >>> r.read() > b'' Because there is no body in a HEAD request. What is useful are the Content-Type, Content-Length, and etag headers. Is r.getcode() == 200? That indicates a successful response; you *always* much check the response code before interpreting the response. Also I'm pretty sure that "HTTP 1.0" is wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python in a shell script
rusi wrote: > On Jun 17, 6:05 am, Chris Angelico wrote: > >> > Python call becomes. I'd prefer something like: >> >> #!/bin/bash >> for i in 1 2 3 4; do >> python -c "if True: > # comfortably indented python code > > Thanks. Nice! You can use bash here document feature, <<-, that strips heading tab characters but not spaces. #!/bin/bash for i in 1 2 3 4; do python /dev/stdin <<-EOF for i in range($i): print i # two tabs and four spaces EOF done Or alternatively you can use a temporary file: #!/bin/bash TEMPFILE=$(mktemp) trap 'rm -f $TEMPFILE' TERM INT cat > $TEMPFILE
Re: HTTPConncetion - HEAD request
On Fri, Jun 17, 2011 at 6:19 PM, gervaz wrote: > The fact is that I have a list of urls and I wanted to retrieve the > minimum necessary information in order to understand if the link is a > valid html page or e.g. a picture or something else. As far as I > understood here http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html > the HEAD command is the one that let you do this. But it seems it > doesn't work. It's not working because of a few issues. Twitter doesn't accept requests that come without a Host: header, so you'll need to provide that. Also, your "HTTP 1.0" is going as the body of the request, which is quite unnecessary. What you were getting was a 301 redirect, as you can confirm thus: >>> r.getcode() 301 >>> r.getheaders() [('Date', 'Fri, 17 Jun 2011 08:31:31 GMT'), ('Server', 'Apache'), ('Location', 'http://twitter.com/'), ('Cache-Control', 'max-age=300'), ('Expires', 'Fri, 17 Jun 2011 08:36:31 GMT'), ('Vary', 'Accept-Encoding'), ('Connection', 'close'), ('Content-Type', 'text/html; charset=iso-8859-1')] (Note the Location header - the server's asking you to go to twitter.com by name.) h.request("HEAD","/",None,{"Host":"twitter.com"}) Now we have a request that the server's prepared to answer: >>> r.getcode() 200 The headers are numerous, so I won't quote them here, but you get a Content-Length which tells you the size of the page that you would get, plus a few others that may be of interest. But note that there's still no body on a HEAD request: >>> r.read() b'' If you want to check validity, the most important part is the code: >>> h.request("HEAD","/aasdfadefa",None,{"Host":"twitter.com"}) >>> r=h.getresponse() >>> r.getcode() 404 Twitter might be a bad example for this, though, as the above call will succeed if there is a user of that name (for instance, replacing "/aasdfadefa" with "/rosuav" changes the response to a 200). You also have to contend with the possibility that the server won't allow HEAD requests at all, in which case just fall back on GET. But all this isn't certain, even so. There are some misconfigured servers that actually send a 200 response when a page doesn't exist. But you can probably ignore those sorts of hassles, and just code to the standard. Hope that helps! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTPConncetion - HEAD request
On 17 Giu, 01:00, Ian Kelly wrote: > On Thu, Jun 16, 2011 at 4:43 PM, gervaz wrote: > > Hi all, can someone tell me why the read() function in the following > > py3 code returns b''? > > h = http.client.HTTPConnection("www.twitter.com") > h.connect() > h.request("HEAD", "/", "HTTP 1.0") > r = h.getresponse() > r.read() > > b'' > > You mean why does it return an empty byte sequence? Because the HEAD > method only requests the response headers, not the body, so the body > is empty. If you want to see the response body, use GET. > > Cheers, > Ian The fact is that I have a list of urls and I wanted to retrieve the minimum necessary information in order to understand if the link is a valid html page or e.g. a picture or something else. As far as I understood here http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html the HEAD command is the one that let you do this. But it seems it doesn't work. Any help? Mattia -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
On 17/06/2011 06:06, John Salerno wrote: Based on what I've read, it seems os.rename is the proper function to use, but I'm a little confused about the syntax. Basically I just want to write a simple script that will back up my saved game files when I run it. So I want it to copy a set of files/directories from a location on my C:\ drive to another directory on my E:\ drive. I don't want to rename or delete the originals, just move them. I also want them to automatically overwrite whatever already happens to be in the location on the E:\ drive. Is os.rename the proper function for this? Mainly I was because the Module Index says this: "On Windows, if dst already exists, OSError will be raised even if it is a file.." so it sounds like I can't move the files to a location where those file names already exist. For a Windows-only Q&D, you could use the pywin32 win32file module which exposes the MoveFileEx[W] API: import win32file win32file.MoveFileExW ( "c:/temp/blah.txt", "c:/temp/blah2.txt", win32file.MOVEFILE_REPLACE_EXISTING ) TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Run Python script from JS
On Fri, Jun 17, 2011 at 9:11 AM, Gnarlodious wrote: > Is there any way to call a Py script from Javascript in a webpage? You can use Pyjamas [1], Emscripten [2] or skulpt [3] for that. [1] http://pyjs.org/ [2] http://syntensity.com/static/python.html [3] http://www.skulpt.org/ -- With best regards, Daniel Kluev -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you copy files from one location to another?
John Salerno wrote: I want it to copy a set of files/directories from a location on my C:\ drive to another directory on my E:\ drive. I don't want to rename or delete the originals, It sounds like shutil.copy() is what you want, or one of the other related functions in the shutil module. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Missing python27.dll on Win 7 64-bit
Hi I am building a 32-bit C++ application using Visual C++ Express 2008 on 64-bit Windows 7. The application links to Python, so I installed 32-bit Python 2.7.2 by running python-2.7.2.msi. When I run my app, I get error: ... python27.dll is missing from your computer ... and, indeed, it is in neither C:\Windows\System32 nor C:\Windows\SysWOW64. Please will someone suggest what I am doing wrong? Best regards David -- http://mail.python.org/mailman/listinfo/python-list
Re: break in a module
Steven D'Aprano wrote: On Thu, 16 Jun 2011 22:20:50 -0700, Erik Max Francis wrote: [...] Yes, which could be rephrased as the fact that `break` and `continue` are restricted to looping control structures, so reusing `break` in this context would be a bad idea. You know, kind of like the exact point I made earlier which you're trying to nitpick in another reply. No offense is intended Erik, but in my experience, when people complain about others nitpicking, they've usually said something which is *almost* correct, i.e. wrong :) Can we agree that the plain English verb "break", as in "to break out of", can apply to any of: This is all great and all, but specific references earlier in the thread were made to not just the concept of "breaking out of things," but to the `break`, `continue` (not relevant here), and `return` keywords. It was these that I was discussing. I simply pointed out why the first and last were not good ideas for consistency reasons (the second was never proposed as a good idea). And, most importantly, why the whole idea is not that useful to start with; there already exist far better ways to achieve your goals that are already supported in the language, clear, and self-documenting if used properly. -- Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis Do we really want to go to Mars / Do we really want to try -- Cassandra Wilson -- http://mail.python.org/mailman/listinfo/python-list
Re: Run Python script from JS
for xhtml wouldnt the syntax be