Python/pyobjC Apps on iPhone now a possibility?
I have been following the discussion about python and pyobjc on the iphone, and it seemed to me that the app-store rules prohibited embedded interpreters; so, python apps are a no-no. But now it seems that the Rubyists have the option that we don't. It seems there is a company, http://rhomobile.com/home, that has an SDK that allows ruby programs to be embedded together with an interpreter in an app! More interesting is the fact that several of these hybrid apps seem to have been accepted on the itunes app store. Here's a quote from a representative, found on this blog: http://www.rubyinside.com/rhodes-develop-full-iphone-rim-and-symbian-apps-using-ruby-1475.html ...First of all, to clarify, we precompile all framework and app code down to Ruby 1.9 VM bytecode. This yields great performance advantages. We also disable eval and other dynamic execution aspects of Ruby. In the end, on all platforms your app gets compiled with our framework all into one single executable, indistinguishable from any other executable. But even if we were shipping a fullon Ruby interpreter without compiling to bytecode and leaving dynamic evaluation enabled (as has been well remarked in the blogosphere by now) App Store rule 3.3.2 does not disallow interpreters but only downloading code to be executed by the interpreter. So, the question is, can the same thing be done for Python apps? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/pyobjC Apps on iPhone now a possibility?
Sure, I am learning Objective C already, but the syntax is really unfriendly after python. I think it really depends on the type of app you want to write. Anything held back by network delays or that sits around waiting for user input are perfectly acceptable target apps. If you need speed for something really intensive, falling back to C is still much nicer than coding in Objective C. I agree that having a certain basic understanding of objective C is a must, but having the option to use a coder-friendly language like Ruby or Python can cut development time dramatically. If Ruby can do it (and it generally slower than python), why can Python also get a legal iPhone interpreter? -- http://mail.python.org/mailman/listinfo/python-list
namespace query
Hi, I have a quick question about global namespace, and I'm hoping someone could give a quick reply to sort me out :) I have a single file program that uses numpy, and it works just fine. I want to move some classes into their own files, to make the code reusable. When I cut and paste the the classes into new files, and then import them back into the original program, I get an error,:NameError: name 'numpy' is not defined, called about the new class files. If I add a global numpy to the beginning of each class in the new files, the program runs. Do I really have to add global XXX for every module I import in the main program into every module I create and import? Why are the class files I created not seeing the top namespace? Thanks in Advance! Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: namespace query
ok, sorted. I had thought that when a module was imported, it was added to a larger shared namespace used by all the modules. And yes, you are all correct; the global numpy thing was an illusion caused by saving the file at the wrong time after making a few changes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling modules in OSX, eg PyUSB?
On Mar 20, 6:23 pm, Philip Semanchuk phi...@semanchuk.com wrote: On Mar 20, 2009, at 12:36 PM, Dr Mephesto wrote: windows? well, I thought that maybe the location of the usb.h thing was relevant, and I didnt see it mentioned on the linux instructions. Oh, OK. Windows is a pretty different animal from Unix/Linux so it's not likely to be of much help here. find /usr -name usb.h -ls gives me: 3545683 24 -rw-r--r-- 1 root wheel 8360 Mar 20 16:37 /usr/include/usb.h 3538549 24 -rw-rw-r-- 1 root wheel 8360 Feb 22 11:28 /usr/local/include/usb.h Looks good. sudo python setup.py install this gives me: pcfr147:pyusb-0.4.1 david$ sudo python setup.py install Password: running install running build running build_ext building 'usb' extension gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd - fno-common -dynamic -DNDEBUG -g -O3 -I/Library/Frameworks/ Python.framework/Versions/4.1.30101/include/python2.5 -c pyusb.c -o build/temp.macosx-10.3-i386-2.5/pyusb.o In file included from pyusb.c:11: pyusb.h:6:17: error: usb.h: No such file or directory OK, I think I see what's going wrong, but I don't understand it. I think I was wrong; setup.py doesn't automatically add /usr/include and /usr/local/include to the include path when compiling. I'm basing this on the documentation here, which states that these paths have to be added explicitly:http://docs.python.org/distutils/setupscript.html#preprocessor-options However, the two C extensions I distribute compile just fine without that, and they certainly rely on /usr/include and /usr/local/include. Strange... But nevermind that. Looking in the setup.py for PyUSB, I see this special code added for OS X (a.k.a. Darwin): elif -1 != platform.find(darwin): extra_link_args = ['-framework', 'CoreFoundation', '-framework', 'IOKit', '-L/sw/lib'] extra_compile_args = ['-I/sw/include'] The ['-I/sw/include'] tells the compiler what directories to search for include files. The /sw/ tree is specific to Fink, so if you'd used Fink to install libusb then the PyUSB setup would have found it. But you didn't use Fink (nothing wrong with that; I don't either) and so your usb.h landed in /usr/local/include. What you need to do, then, is add that directory to the list. So change line 32 in the PyUSB setup.py from this: extra_compile_args = ['-I/sw/include'] to this: extra_compile_args = ['-I/sw/include', '-I/usr/local/include'] The same assumption is made about the linker path. Note the '-L/sw/ lib'. You'll need to track down your copy of libusb (it's probably in / usr/local/lib) and add that to the extra_link_args like so: extra_link_args = ['-framework', 'CoreFoundation', '-framework', 'IOKit', '-L/sw/lib', '-L/usr/local/lib'] Run setup again and I bet you'll be off to the races. You should certainly report this to the package maintainer, and you might also want to point out that the if block starting on line 17 of setup.py and the if block starting on line 26 are both for OS X, but they lead to different results! Let us know how it works out, Philip Great, that did the job perfectly! Very much appreciated! I will write to the code maintainer to let them know the fix; I'm sure their are lots of other people out there that will find your modification useful. Thanks again, Dave -- http://mail.python.org/mailman/listinfo/python-list
Compiling modules in OSX, eg PyUSB?
Hi, I am using Leopard and MacPython, and I would like to access a USB device. I have installed libusb, and now I have tried to compile PyUSB from: http://sourceforge.net/projects/pyusb/ But when I compile I get lots of errors, ie: pcfr147:pyusb-0.4.1 david$ python setup.py install running install running build running build_ext building 'usb' extension gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd - fno-common -dynamic -DNDEBUG -g -O3 -I/Library/Frameworks/ Python.framework/Versions/4.1.30101/include/python2.5 -c pyusb.c -o build/temp.macosx-10.3-i386-2.5/pyusb.o In file included from pyusb.c:11: pyusb.h:6:17: error: usb.h: No such file or directory In file included from pyusb.c:11: pyusb.h:120: error: syntax error before 'usb_dev_handle' pyusb.h:120: warning: no semicolon at end of struct or union pyusb.h:122: error: syntax error before '}' token pyusb.h:122: warning: data definition has no type or storage class pyusb.h:131: warning: 'struct usb_endpoint_descriptor' declared inside parameter list pyusb.h:131: warning: its scope is only this definition or declaration, which is probably not what you want ... ... pyusb.c:2083: error: dereferencing pointer to incomplete type pyusb.c:2084: warning: passing argument 1 of 'new_Bus' from incompatible pointer type lipo: can't figure out the architecture type of: /var/folders/xt/ xtY5vvWXEUyZv0KZrwtRzTI/-Tmp-//ccYg0qka.out error: command 'gcc' failed with exit status 1 A long time googling found this similar problem: http://ubuntuforums.org/archive/index.php/t-325241.html The suggested answer was to first do: sudo apt-get install python-dev But that was for a debian machine. I dont use fink, and I prefer to use a standard osx python install if possible. I am still a python novice, and I'm not sure if I am using the python setup.py install command wrongly, or if I need this python-dev package, or something completely different. Has anyone had this problem, or know a solution? Thanks in Advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling modules in OSX, eg PyUSB?
Thanks. I found some more info that might help, if I understood it :)From the main PyUSB page, at http://pyusb.berlios.de/ , its says: PyUSB uses the libusb to do its work, so, any system which has Python and libusb should work for PyUSB. I have installed the OSX version of libusb, and it puts the missing file usb.h in the directory: usr/local/include/usb.h In the instruction for installing PyUSB on windows, it says: 2) libusb-win32: a Windows version of the libusb C library available from http://libusb-win32.sourceforge.net. From within a Cygwin terminal, copy the libusb.a file from the libusb-win32 lib/ directory to $(CYGWINDIR)/usr/lib/, and copy the usb.h file from the libusb-win32 include/ directory to $(CYGWINDIR)/usr/include/. You can build and install PyUSB with the command: python setup.py install As I have the required usb.h file, is there some way to let the compiler know where is it when I run python setup.py install? I already tried copying the usb.h file from usr/local/include/ to /usr/ iinclude, but it still didnt find it. Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling modules in OSX, eg PyUSB?
windows? well, I thought that maybe the location of the usb.h thing was relevant, and I didnt see it mentioned on the linux instructions. find /usr -name usb.h -ls gives me: 3545683 24 -rw-r--r--1 root wheel8360 Mar 20 16:37 /usr/include/usb.h 3538549 24 -rw-rw-r--1 root wheel8360 Feb 22 11:28 /usr/local/include/usb.h sudo python setup.py install this gives me: pcfr147:pyusb-0.4.1 david$ sudo python setup.py install Password: running install running build running build_ext building 'usb' extension gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd - fno-common -dynamic -DNDEBUG -g -O3 -I/Library/Frameworks/ Python.framework/Versions/4.1.30101/include/python2.5 -c pyusb.c -o build/temp.macosx-10.3-i386-2.5/pyusb.o In file included from pyusb.c:11: pyusb.h:6:17: error: usb.h: No such file or directory In file included from pyusb.c:11: pyusb.h:120: error: syntax error before 'usb_dev_handle' pyusb.h:120: warning: no semicolon at end of struct or union pyusb.h:122: error: syntax error before '}' token pyusb.h:122: warning: data definition has no type or storage class pyusb.h:131: warning: 'struct usb_endpoint_descriptor' declared inside parameter list pyusb.h:131: warning: its scope is only this definition or declaration, which is probably not what you want pyusb.h:135: warning: 'struct usb_endpoint_descriptor' declared inside parameter list pyusb.h:140: warning: 'struct usb_interface_descriptor' declared inside parameter list pyusb.h:144: warning: 'struct usb_interface_descriptor' declared inside parameter list pyusb.h:149: warning: 'struct usb_config_descriptor' declared inside parameter list pyusb.h:153: warning: 'struct usb_config_descriptor' declared inside parameter list pyusb.h:171: warning: 'struct usb_bus' declared inside parameter list pyusb.h:239: error: syntax error before '*' token pyusb.h:241: warning: data definition has no type or storage class pyusb.c: In function 'getBuffer': pyusb.c:143: warning: passing argument 3 of 'PyString_AsStringAndSize' from incompatible pointer type pyusb.c: In function 'installModuleConstants': pyusb.c:236: error: 'USB_CLASS_PER_INTERFACE' undeclared (first use in this function) pyusb.c:236: error: (Each undeclared identifier is reported only once pyusb.c:236: error: for each function it appears in.) pyusb.c:237: error: 'USB_CLASS_AUDIO' undeclared (first use in this function) pyusb.c:238: error: 'USB_CLASS_COMM' undeclared (first use in this function) pyusb.c:239: error: 'USB_CLASS_HID' undeclared (first use in this function) pyusb.c:240: error: 'USB_CLASS_PRINTER' undeclared (first use in this function) pyusb.c:241: error: 'USB_CLASS_MASS_STORAGE' undeclared (first use in this function) pyusb.c:242: error: 'USB_CLASS_HUB' undeclared (first use in this function) pyusb.c:243: error: 'USB_CLASS_DATA' undeclared (first use in this function) pyusb.c:244: error: 'USB_CLASS_VENDOR_SPEC' undeclared (first use in this function) pyusb.c:245: error: 'USB_DT_DEVICE' undeclared (first use in this function) pyusb.c:246: error: 'USB_DT_CONFIG' undeclared (first use in this function) pyusb.c:247: error: 'USB_DT_STRING' undeclared (first use in this function) pyusb.c:248: error: 'USB_DT_INTERFACE' undeclared (first use in this function) pyusb.c:249: error: 'USB_DT_ENDPOINT' undeclared (first use in this function) pyusb.c:250: error: 'USB_DT_HID' undeclared (first use in this function) pyusb.c:251: error: 'USB_DT_REPORT' undeclared (first use in this function) pyusb.c:252: error: 'USB_DT_PHYSICAL' undeclared (first use in this function) pyusb.c:253: error: 'USB_DT_HUB' undeclared (first use in this function) pyusb.c:254: error: 'USB_DT_DEVICE_SIZE' undeclared (first use in this function) pyusb.c:255: error: 'USB_DT_CONFIG_SIZE' undeclared (first use in this function) pyusb.c:256: error: 'USB_DT_INTERFACE_SIZE' undeclared (first use in this function) pyusb.c:257: error: 'USB_DT_ENDPOINT_SIZE' undeclared (first use in this function) pyusb.c:258: error: 'USB_DT_ENDPOINT_AUDIO_SIZE' undeclared (first use in this function) pyusb.c:259: error: 'USB_DT_HUB_NONVAR_SIZE' undeclared (first use in this function) pyusb.c:260: error: 'USB_MAXENDPOINTS' undeclared (first use in this function) pyusb.c:261: error: 'USB_ENDPOINT_ADDRESS_MASK' undeclared (first use in this function) pyusb.c:262: error: 'USB_ENDPOINT_DIR_MASK' undeclared (first use in this function) pyusb.c:263: error: 'USB_ENDPOINT_TYPE_MASK' undeclared (first use in this function) ... and lots lots more. do you want the whole lot? It still cant find that usb.h file. dave -- http://mail.python.org/mailman/listinfo/python-list
quick beginners List comprehension question
Hi, Im new to python, and OOP, and am trying to get a handle on list comprehension. Say I have a class Foo with a property called bar: class Foo: def __init__(self): self.bar = random.randint(1,100) and then I make a list of these objects: Newlist = [] for x in range(10): Newlist.append(Foo()) Now, suppose I wanted to triple the value of 'bar', I could always do: for x in range(10): Newlist[x].bar = Newlist[x].bar * 3 but can I do this using list comprehension? Thanks in Advance! -- http://mail.python.org/mailman/listinfo/python-list
App idea, Any idea on implementation?
Hi Guru's, As a python newb, I was thinking about trying to implement a program that converts whistled music into midi; the idea coming from a proposed application in the Mydreamapp competition hosted last year, more details here: http://stratfordisland.com/whistler/ So, does anyone have a suggestion as to the best way to implement this? I was thinking maybe a fast fourier ever 20th of a second, selecting the dominant frequency, and then mapping that onto a real musical scale, then stretching or cutting the notes to a preselected timing scheme. Is this a stupid idea? Can one do a real time fourier transform in python? Or is there some other way to find the frequency of a whistle easily? I want to do this in real time, so as you whistle a tune, you see the notes appear, but if this is too hard, the prerecorded should be also good I guess. Im just looking for some vague opinion on how to start, so please post any idea you might have, every thing helps! Also, If you know of any code that already exist that might help, please post a link! Thanks in Advance, Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: App idea, Any idea on implementation?
thanks for the pointers! I just found a program that does more or less what I want, but I would still like to have a go myself. The link is: http://www.akoff.com/music-composer.html I gave the program a go, as there is a free trial. I found that it had a hard time doing the conversion (or I am a really bad whistler), maybe there is room for improvements. So, I know it can be done, the question is, does Python have to power to do it? And how did they actually do it anyway... -- http://mail.python.org/mailman/listinfo/python-list
Re: creating really big lists
On Sep 8, 8:06 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Dr Mephesto a écrit : Hi! I would like to create a pretty big list of lists; a list 3,000,000 long, each entry containing 5 empty lists. My application will append data each of the 5 sublists, so they will be of varying lengths (so no arrays!). Does anyone know the most efficient way to do this? Hem... Did you consider the fact that RAM is not an unlimited resource? Let's do some simple math (please someone correct me if I'm going off the road): if a Python (empty) list object required 256 bits (if I refer to some old post by GvR, it's probably more - 384 bytes at least. Some Python guru around ?), you'd need (1 + (300 * 5)) * 256 bits just to build this list of lists. Which would make something around 3 Gb. Not counting all other needed memory... FWIW, run the following code: # eatallramthenswap.py d = {} for i in xrange(300): d[i] = ([], [], [], [], []) And monitor what happens with top... Unused ram is wasted ram :) I tried using MySQL, and it was to slow. and I have 4gb anyway... -- http://mail.python.org/mailman/listinfo/python-list
Re: creating really big lists
On Sep 8, 3:33 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Fri, 07 Sep 2007 16:16:46 -0300, Dr Mephesto [EMAIL PROTECTED] escribi?: hey, that defaultdict thing looks pretty cool... whats the overhead like for using a dictionary in python? Dictionaries are heavily optimized in Python. Access time is O(1), adding/removing elements is amortized O(1) (that is, constant time unless it has to grow/shrink some internal structures.) -- Gabriel Genellina well, I want to (maybe) have a dictionary where the value is a list of 5 lists. And I want to add a LOT of data to these lists. 10´s of millions of pieces of data. Will this be a big problem? I can just try it out in practice on monday too :) thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: creating really big lists
On 6 Sep., 09:30, Paul McGuire [EMAIL PROTECTED] wrote: On Sep 6, 12:47 am, Dr Mephesto [EMAIL PROTECTED] wrote: I need some real speed! a database is waaay to slow for the algorithm im using. and because the sublists are of varying size, i dont think I can use an array...- Hide quoted text - - Show quoted text - How about a defaultdict approach? from collections import defaultdict dataArray = defaultdict(lambda : [[],[],[],[],[]]) dataArray[1001][3].append('x') dataArray[42000][2].append('y') for k in sorted(dataArray.keys()): print %6d : %s % (k,dataArray[k]) prints: 1001 : [[], [], [], ['x'], []] 42000 : [[], [], ['y'], [], []] -- Paul hey, that defaultdict thing looks pretty cool... whats the overhead like for using a dictionary in python? dave -- http://mail.python.org/mailman/listinfo/python-list
creating really big lists
Hi! I would like to create a pretty big list of lists; a list 3,000,000 long, each entry containing 5 empty lists. My application will append data each of the 5 sublists, so they will be of varying lengths (so no arrays!). Does anyone know the most efficient way to do this? I have tried: list = [[[],[],[],[],[]] for _ in xrange(300)] but its not s fast. Is there a way to do this without looping? David. -- http://mail.python.org/mailman/listinfo/python-list
Re: creating really big lists
yep, thats why I'm asking :) On Sep 5, 12:22 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Paul Rudin wrote: Dr Mephesto [EMAIL PROTECTED] writes: Hi! I would like to create a pretty big list of lists; a list 3,000,000 long, each entry containing 5 empty lists. My application will append data each of the 5 sublists, so they will be of varying lengths (so no arrays!). Does anyone know the most efficient way to do this? I have tried: list = [[[],[],[],[],[]] for _ in xrange(300)] but its not s fast. Is there a way to do this without looping? You can do: [[[],[],[],[],[]]] * 300 although I don't know if it performs any better than what you already have. You are aware that this is hugely different, because the nested lists are references, not new instances? Thus the outcome is most probably (given the gazillion of times people stumbled over this) not the desired one... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: creating really big lists
On 6 Sep., 01:34, Delaney, Timothy (Tim) [EMAIL PROTECTED] wrote: Hrvoje Niksic wrote: Dr Mephesto [EMAIL PROTECTED] writes: I would like to create a pretty big list of lists; a list 3,000,000 long, each entry containing 5 empty lists. My application will append data each of the 5 sublists, so they will be of varying lengths (so no arrays!). Does anyone know the most efficient way to do this? I have tried: list = [[[],[],[],[],[]] for _ in xrange(300)] If you're building large data structures and don't need to reclaim cyclical references, I suggest turning GC off, at least during construction. This is good advice, but another question is whether you really want such a list. You may well be better off with a database of some kind - they're designed for manipulating large amounts of data. Tim Delaney I need some real speed! a database is waaay to slow for the algorithm im using. and because the sublists are of varying size, i dont think I can use an array... -- http://mail.python.org/mailman/listinfo/python-list