Re: How to read a binary file into a mysql table
On Dec 14, 5:41 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 14 Dec 2007 12:19:41 -0300, Hans Müller <[EMAIL PROTECTED]> escribió: > > > I cannot read a binary file into a mysql database. Everything I tried > > did not succeed. > > > What I tried (found from various google lookups...) is this: > > > con = MySQLdb.connect(to server) > > cur = con.cursor() > > > cur.execute("insert into data values('file1', %s)", (open("test.jpg", > > "rb").read(), )) > > Try wrapping the file contents with a Binary object (untested): > > data = MySQLdb.Binary(open("test.jpg","rb").read()) > cur.execute("insert into data values('file1', %s)", (data,)) > > -- > Gabriel Genellina I was suprised at what I could stick into a MySQL database. Also, you might wanna compress the binary for database performance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Yet another comparison of Python Web Frameworks
Gluon was made at my school? I seriously gotta start talking to the CTI department. -- http://mail.python.org/mailman/listinfo/python-list
Suggested Reading
I got myself into programming late in the summer and have dabbled in python for the most part in that time, recently beginning work on a music player. In January, I start my minor in Information Technology. I'd like to get ahead a bit, however, and over the break would like to do some reading. I seek your recommendations in the field of database design basics and network programming, with a bias towards texts which specifically address Python. By network programming, I mean fundamental understanding of sockets, TCP/UDP, right up to HTTP serving, etc. Thanks ahead of time. -- http://mail.python.org/mailman/listinfo/python-list
Is there *any* real documentation to PyWin32?
I understand that the Win32 has been said to be itself poorly documented, so perhaps that the documentation that comes with the modules is of similar quality is no coincidence. Maybe I'm still too young in my programming to grasp the good of that documentation, but for myself, it tells me next to nothing. Could anyone point me to anything which may exist that does a better job of explaining the extensions' use? I tried to take a look @ Microsoft's documentation, but it was confusing. -- http://mail.python.org/mailman/listinfo/python-list
Pythons & Ladders
I've been teaching myself the python language over the past few months using Mark Lutz' Learning Python, 3ed. Python is also the first programming language I've ever taken up. I find the language easy to learn and rather productive in relation to the introductory course on C ++ I'd begun in January for fun @ school (we're practicing dynamic arrays using pointers... kill me now). My problem, however, is that I found myself lacking problems with which to create solutions and so practice what I've learned. I think I'm one of those people who really get into something when the instructions come from without. So I'd like to ask you resident python gurus to help me learn. Give me something to do! Specifically, I'd like to be given tasks that incrementally increase in difficulty, starting from simple file/text manipulation to those harder things like built-in function overloading (you know, where you can make the "+" operator do something different in relation to a given object). I hope my request doesn't come off as demanding, as perhaps we could archive these tasks for future pedagogy. If something like this already exists though, please point me in the right direction. Otherwise, thanks for any and all assistance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythons & Ladders
On Feb 27, 5:24 pm, Benoit <[EMAIL PROTECTED]> wrote: > I've been teaching myself the python language over the past few months > using Mark Lutz' Learning Python, 3ed. Python is also the first > programming language I've ever taken up. I find the language easy to > learn and rather productive in relation to the introductory course on C > ++ I'd begun in January for fun @ school (we're practicing dynamic > arrays using pointers... kill me now). My problem, however, is that I > found myself lacking problems with which to create solutions and so > practice what I've learned. I think I'm one of those people who > really get into something when the instructions come from without. > > So I'd like to ask you resident python gurus to help me learn. Give > me something to do! Specifically, I'd like to be given tasks that > incrementally increase in difficulty, starting from simple file/text > manipulation to those harder things like built-in function overloading > (you know, where you can make the "+" operator do something different > in relation to a given object). I hope my request doesn't come off as > demanding, as perhaps we could archive these tasks for future > pedagogy. > > If something like this already exists though, please point me in the > right direction. Otherwise, thanks for any and all assistance. Just some background: My main thing is XHTML/CSS, and we're on javascript in my Web Design course. I'm ultimately interested in dynamic website design. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythons & Ladders
Forgive my language concerning C++ as its turned the thread into something I did not intend. I merely wished to point out that Python was easier for me to learn than C++. To Schwab, its likely that Mark Lutz is simply a better instructor than my professor. -- http://mail.python.org/mailman/listinfo/python-list
Re: global variable not working inside function. Increment
On Friday, September 4, 2009 4:52:11 PM UTC-7, Rami Chowdhury wrote: > > global no_picked > > no_picked = 0 > > > > def picked(object, event): > > no_picked += 1 > > print no_picked > > In order to be able to affect variables in the global scope, you need to > declare them global inside the function, and not at the global scope. So > your code should read: > > no_picked = 0 > > def picked(object, event): > global no_picked > no_picked += 1 > print no_picked > > I believe that will work. > > On Fri, 04 Sep 2009 16:43:27 -0700, Helvin wrote: > > > Hi, > > > > This increment thing is driving me nearly to the nuts-stage. > < > > > > I have a function that allows me to pick points. I want to count the > > number of times I have picked points. > > > > global no_picked > > no_picked = 0 > > > > def picked(object, event): > > no_picked += 1 > > print no_picked > > > > Error msg says: UnboundLocalError: local variable 'no_picked' > > referenced before assignment > > For some reason, no_picked does not increment, but the printing > > statement works. > > > > Do you know why? > > > > (I'm actually writing this for a vtkrenderwindowinteractor.) > > > > Helvin > > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
python adds an extra half space when reading from a string or list
number_drawn=() def load(lot_number,number_drawn): first=input("enter first lot: ") last=input("enter last lot: ") for lot_number in range(first,last): line_out=str(lot_number) for count in range(1,5): number_drawn=raw_input("number: ") line_out=line_out+(number_drawn) print line_out finale_line.append(line_out) finale_line2=finale_line load(lot_number,number_drawn) print finale_line print(" "*4), for n in range(1,41): print n, #this is to produce a line of numbers to compare to output# for a in finale_line: print"\n", print a[0]," ", space_count=1 for b in range(1,5): if int(a[b])<10: print(" "*(int(a[b])-space_count)),int(a[b]), space_count=int(a[b]) else: print(" "*(a[b]-space_count)),a[b], space_count=a[b]+1 number_drawn=() def load(lot_number,number_drawn): first=input("enter first lot: ") last=input("enter last lot: ") for lot_number in range(first,last): line_out=str(lot_number) for count in range(1,5): number_drawn=raw_input("number: ") line_out=line_out+(number_drawn) print line_out finale_line.append(line_out) finale_line2=finale_line load(lot_number,number_drawn) print finale_line print(" "*4), for n in range(1,41): print n, #this is to produce a line of numbers to compare to output# for a in finale_line: print"\n", print a[0]," ", space_count=1 for b in range(1,5): if int(a[b])<10: print(" "*(int(a[b])-space_count)),int(a[b]), space_count=int(a[b]) else: print(" "*(a[b]-space_count)),a[b], space_count=a[b]+1 this generates enter first lot: 1 enter last lot: 4 number: 2 number: 3 number: 4 number: 5 12345 number: 1 number: 2 number: 3 number: 4 21234 number: 3 number: 4 number: 5 number: 6 33456 ['12345', '21234', '33456'] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 1 2 3 4 5 21 2 3 4 3 3 4 5 6 >#as you can see many numbers are between the lines of a normal print# #I thought this was due to "white space" int he format .So I tried a list of strings and got the same results.# -- http://mail.python.org/mailman/listinfo/python-list
Re: Cygwin and Python3
Larry Hudson writes: >> Hi, I am having a hard time making my Cygwin run Python 3.5 (or >> Python 2.7 for that matter). >> The command will hang and nothing happens. > > Just curious... > > Since Python runs natively in Windows, why are you trying to run it > with Cygwin? I'm not implying that you shouldn't, just offhand I don't > see a reason for it. I do it because it's easier to install third party packages, those that need an external library to run. Cygwin come with a lot of lib* and lib*-devel that permit to just run `pip install xxx' if not already packaged. I gave a try on the native Windows version and Anaconda but there is at least one package that I could not run (and I loosed a lot of time to compile a bunch of libraries). Example of package: pyproj (proj4), openpyxl with lxml (libxml2, libxslt) and pillow (libjpeg, zlib, libtiff, ...), psycopg2 (libpq). -- Benoit Izac -- https://mail.python.org/mailman/listinfo/python-list
Re: Cygwin and Python3
Terry Reedy writes: >>> Since Python runs natively in Windows, why are you trying to run it >>> with Cygwin? I'm not implying that you shouldn't, just offhand I don't >>> see a reason for it. >> >> I do it because it's easier to install third party packages, those that >> need an external library to run. Cygwin come with a lot of lib* and >> lib*-devel that permit to just run `pip install xxx' if not already >> packaged. I gave a try on the native Windows version and Anaconda but >> there is at least one package that I could not run (and I loosed >> a lot of time to compile a bunch of libraries). >> >> Example of package: pyproj (proj4), openpyxl with lxml (libxml2, >> libxslt) and pillow (libjpeg, zlib, libtiff, ...), psycopg2 (libpq). > > I belive these are all available at > http://www.lfd.uci.edu/~gohlke/pythonlibs/ How do you know when an upgrade is avaible? -- Benoit Izac -- https://mail.python.org/mailman/listinfo/python-list
Re: Cygwin and Python3
Terry Reedy writes: >>> Since Python runs natively in Windows, why are you trying to run it >>> with Cygwin? I'm not implying that you shouldn't, just offhand I don't >>> see a reason for it. >> >> I do it because it's easier to install third party packages, those that >> need an external library to run. Cygwin come with a lot of lib* and >> lib*-devel that permit to just run `pip install xxx' if not already >> packaged. I gave a try on the native Windows version and Anaconda but >> there is at least one package that I could not run (and I loosed >> a lot of time to compile a bunch of libraries). >> >> Example of package: pyproj (proj4), openpyxl with lxml (libxml2, >> libxslt) and pillow (libjpeg, zlib, libtiff, ...), psycopg2 (libpq). > > I belive these are all available at > http://www.lfd.uci.edu/~gohlke/pythonlibs/ How do you know when an upgrade is available? -- Benoit Izac -- https://mail.python.org/mailman/listinfo/python-list
Large list in memory slows Python
Hi. I am experiencing a puzzling problem with both Python 2.4 and Python 2.6 on CentOS 5. I'm looking for an explanation of the problem and possible solutions. Here is what I did: Python 2.4.3 (#1, Sep 21 2011, 19:55:41) IPython 0.8.4 -- An enhanced Interactive Python. In [1]: def test(): ...: return [(i,) for i in range(10**6)] In [2]: %time x = test() CPU times: user 0.82 s, sys: 0.04 s, total: 0.86 s Wall time: 0.86 s In [4]: big_list = range(50 * 10**6) In [5]: %time y = test() CPU times: user 9.11 s, sys: 0.03 s, total: 9.14 s Wall time: 9.15 s As you can see, after creating a list of 50 million integers, creating the same list of 1 million tuples takes about 10 times longer than the first time. I ran these tests on a machine with 144GB of memory and it is not swapping. Before creating the big list of integers, IPython used 111MB of memory; After the creation, it used 1664MB of memory. Thanks for your time. Cheers. -- Benoit Thiell The SAO/NASA Astrophysics Data System http://adswww.harvard.edu/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Large list in memory slows Python
On Tue, Jan 3, 2012 at 5:59 PM, Peter Otten <__pete...@web.de> wrote: > Benoit Thiell wrote: > >> I am experiencing a puzzling problem with both Python 2.4 and Python >> 2.6 on CentOS 5. I'm looking for an explanation of the problem and >> possible solutions. Here is what I did: >> >> Python 2.4.3 (#1, Sep 21 2011, 19:55:41) >> IPython 0.8.4 -- An enhanced Interactive Python. >> >> In [1]: def test(): >> ...: return [(i,) for i in range(10**6)] >> >> In [2]: %time x = test() >> CPU times: user 0.82 s, sys: 0.04 s, total: 0.86 s >> Wall time: 0.86 s >> >> In [4]: big_list = range(50 * 10**6) >> >> In [5]: %time y = test() >> CPU times: user 9.11 s, sys: 0.03 s, total: 9.14 s >> Wall time: 9.15 s >> >> As you can see, after creating a list of 50 million integers, creating >> the same list of 1 million tuples takes about 10 times longer than the >> first time. >> >> I ran these tests on a machine with 144GB of memory and it is not >> swapping. Before creating the big list of integers, IPython used 111MB >> of memory; After the creation, it used 1664MB of memory. > > In older Pythons the heuristic used to decide when to run the cyclic garbage > collection is not well suited for the creation of many objects in a row. > Try switching it off temporarily with > > import gc > gc.disable() > # create many objects that are here to stay > gc.enable() > > You may also encorporate that into your test function: > > def test(): > gc.disable() > try: > return [...] > finally: > gc.enable() Thanks Peter, this is very helpful. Modifying my test according to your directions produced much more consistent results. Benoit. -- Benoit Thiell The SAO/NASA Astrophysics Data System http://adswww.harvard.edu/ -- http://mail.python.org/mailman/listinfo/python-list
Why nested scope rules do not apply to inner Class?
Hi, I'd like to be able to use a nested class (C1) from another sibling nested class (C3). This looks very similar to the nested scopes of functions except that it does not work. class A(object): pass class B(object): class C1(object): pass class C2(C1): foo = A class C3(object): foo = C1 The funny thing is that C2 can inherit from C1 but C3 cannot reference C1. B.C1 does not work either, but in that case it makes sense since B is still being defined. Is this a language limitation or something that does not make sense at all? I'm wondering as well if the new nonlocal statement will fix that in py3k? Thanks in advance, Benoit -- http://mail.python.org/mailman/listinfo/python-list
RE: Why nested scope rules do not apply to inner Class?
> This is a language limitation. > This is because nested scope is implemented for python function only since > 2.3 > allow late binding of free variables. the scope in class statment is not a > closure, so there is only two possible scope in it : local and global. That was my understanding as well, but I think it is a pity to have that limitation. Don't you think that the same improvement that was done for method nested scope could be done as well for nested class? I can easily fix my current issue by doing the binding after the class declaration. My concern is more about the lack of symmetry of that approach; meaning that if both classes are in the global scope, one can access the others, whereas if they are in the body of another class they cannot. This is OK: class A(object): pass class B(object): foo=A I have to add the binding after the declaration in the case of nested: class C(object): class A(object): pass class B(object): foo=None B.foo = A That extra step is a little bit painful and should not be necessary for my point of view. > > I'm wondering as well if the new nonlocal statement will fix that in > py3k? > > > > nonlocal doesn't adress this issue an I doubt python 3.0 fix it at all. > > You have the same problem with generator expressions, which bind lately > outer > loop variables : Good to know, I was not aware of that. Thanks, Benoit -- http://mail.python.org/mailman/listinfo/python-list
RE: Why nested scope rules do not apply to inner Class?
> Defining it as a nested class saves you one line > of code, but IMHO makes the result just a bit more cluttered, while > reducing the elegance of reusing the metaclass. The whole point of nested class is to avoid polluting the namespace with classes that are only used locally. So the argument about the elegance of reusing is not very valid in that case. I agree that they are other ways using module to avoid namespace pollution, but in some case it is easier to use nested class instead and keep everything in the same file. In my case, I'm trying to use a similar approach as XIST's one, meaning using Python class to model hierarchical data. So clearly nested class is a very nice and easy understandable way to do that. > Here are only a few examples of threads giving good reasons against > class nesting. I've never seen any good arguments for it. There are > dozens of good reasons we don't encourage it and won't actively > support it. > > http://mail.python.org/pipermail/python-dev/2005-March/052454.html > http://mail.python.org/pipermail/python-dev/2002-November/029872.html >From what I quickly read in these email threads, except for the pickling issue >and the fact that Guido does not like nested classes, I do not see strong >argument against it either. Regards, Benoit -- http://mail.python.org/mailman/listinfo/python-list
RE: Why nested scope rules do not apply to inner Class?
> > There is no point of nested classes because nested classes _are not_ > supported by python. They are simply an artifact of not actively > denying the syntax non-globally. I would fully support a change to the > language to actively forbid a class definition that is not > module-level. > > > In my case, I'm trying to use a similar approach as XIST's one, meaning > using Python class to model hierarchical data. So clearly nested class is > a very nice and easy understandable way to do that. > > I don't find that this is clear in anyway. I can't imagine why you'd > think a nested class is even useful here, rather than an instance with > some understandable attributes. I've seen a lot of places nested > classes are used and not one of them that should be been doing it. > > But, on that note, there is a point where a discussion is obviously > not going to resolve with either side changing their minds. This is > obviously such a case. I don't think so; my original email was mainly a question. I do agree that they are other ways to do what I'm trying to achieve; there are always several ways to solve an issue. Few days ago, I decided to use nested class because I realized that it was the most convenient way to implement my need. Since this feature is supported in many languages, I was just surprised that Python did support it only partially, hence my original email. Now if you say; it is not supported, don't do that, we will deprecate that feature, fine, I will use an alternative solution. I was just not aware of that "nested class is evil" group in the Python community. I still not understand why, but if it is the BDFL decision... Regards, Benoit -- http://mail.python.org/mailman/listinfo/python-list
I can't run python on my computer
Hi,it has been about a week since the last time I was able to use Python. Most of the time, the interpreter doesn't show up and when it does and I am trying to run a program it displayed the following message: "IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection." Can you please help me with this. It'd be a huge help. Thank you very much. -- https://mail.python.org/mailman/listinfo/python-list