[Tutor] Is this called a 'Hash table method for string mapping'
Dear group, for mapping a string of protein/nucleotides, BLAST is one tool that is highly sought. However, its performance is limited due to some factors and one such factor is length of the query string. IF the length of the query string is less than 30 characters, its output is questionable. So, what if one has to map a string of 15 character nucleotide to a jumbo string of characters of length in millions. The simplest solution to this could be string matching. A researcher from NCI (National Cancer Institute) said to map 500 thousand strings of nucleotides(length of string - 21), they used a hash-table method to map them on the a chromosome (say 15million length of string). I do not know what exactly could be a hash-table method. I tried a simplest way of mapping. Could tutors comment on this method of mapping. # Target string # a = 'GATGAAGACTTGCAGCGTGGACACTGGCCCAGGGGTCGCTAAGGAGCTCCGGCAGCTAGGCGCGGAGATGTGCCCGAACGTCCCACCCTGCTGCACTCTCCTTGCTACTGATTCCTCTGGGCCTCCCAGTCCTCTGTGCTCACGCCTCATCTGCGACAGTCGAGTTCTGGAGAGGTACATCTTAGAGGCCAAGGAGGCAGTGTCACGATGGGTTGTGCAGAAGGTCCCAGACTGAGTGTATTACAGTCCCAGATACCAAAGTCAACTTCTATGCTTGGGAATGGAGGTGGAAGAACAGGCCATAGAAGTTTGGCAAGGCCTGTCCCTGCTCTCAGAAGCCATCCTGCAGGCCCAGGCCCTGCTAGCCAATTCCTCCCAGCCACCAGAGACCCTTCAGCTTCATATAGACAAAGCCATCAGTGGTCTACGTAGCCTCACTTCACTGCTTCGGGTACTGGGAGCTCAGAAGGAATTGATGTCGCCTCCAGATACCAACCTGCTCCACTCCGAACACTCACAGTGGATACTTTCTGCAAGCTCTTCCGGGTCTACGCCAACTTCCTCCGAAACTGAAGCTGTACACGGGAGAGGTCTGCAGGAGAACAGGTGACATGCTGCTGCCACCGTGGTGGACCGACGAACTTGCTGTCACTGTGTCATGCCAACCCTCC' # small query strings# q = ['GCAGGAGAACA', 'GAAGGTCCCAGACTG', 'CCCAGTCCTCTGTGC'] # In the following routine, I sliced the target string into characters of length 15. I created a dictionary of sliced target sequence and its coordinates# dk = [] dv = [] for m in range(len(a)): s = m e = m+15 u = m+1 nd = a[s:e] if len(nd)==15: x = ('%d:%d')%(u,e) dk.append(nd) dv.append(x) sdic = dict(zip(dk,dv)) for r in q: if sdic.has_key(r): print r+'\t'+sdic[r] # result Answer:# GCAGGAGAACA 631:645 GAAGGTCCCAGACTG 240:254 CCCAGTCCTCTGTGC 137:151 my question is : Is this a flavor of hash-table method. Do you think is there any flaw in this. Is there any better method that is possible. Thanks Sri __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does "random" in shuffle( x[, random]) do?
At 03:07 PM 9/3/2006, Luke Paireepinart wrote: [snip] Ah, I'd forgotten that in shuffle( x[, random], "random" would be the default. But please bear with me. Using your function a, I wrote testShuffle.py: # testShuffle.py from random import * def a(): return 0.5 lst = ['1', '2', '3', '4'] shuffle(lst,a) print lst >>> ['1', '4', '2', '3'] >>> Again, this just the random reordering of lst in place. Could you show me a little script where the 2nd argument of shuffle actually does something? no, it's not a random reordering. As others have said already, you can't determine the randomness of a function just by running it once. Why do you think it's a random reordering? If you ran it many times, you'd see why we've been saying that it's important not to test it just once. #--- example script.py from random import shuffle def a(): return 0.5 def run_shuffle(lst): shuffle(lst,a) print lst import copy lst = [1,2,3,4] for x in range(20): tmp = copy.copy(lst) run_shuffle(tmp) #--- end output: [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] [1, 4, 2, 3] >>> So yes, I have already given you an example where the second argument does something. Or do you still think that it's random? :) No, of course not. I answered your reply before I saw the others. What I was hoping for from you was an example using the 2nd argument that does something useful. But you don't need to now. Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] tempfile and webbrowser
> This program works: > ** > import webbrowser > a = open('test.htm','wb') Any particular feason to open the file in binary mode? That can sometimes cause odd things to happen. > a.write("Test") > webbrowser.open(a.name) > a.close() The close should come before the browser reads the file, otherwise you are trying to read a file thats still open in write mode and the behaviouir there is "undefined" on most operating systems. > import tempfile > import webbrowser > a = tempfile.NamedTemporaryFile('w+b',-1,'.html') Now you are making it even more complex by using a read/write mode binary temporary file! > a.write("Test") > webbrowser.open(a.name) > #a.close() > ** > Have you got some suggestions to tackle this problem? Simplify the file handling to use text files and close the file as soon as possible. These are good guidelines for any file handling you do. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pretty_printing
On Mon, Sep 04, 2006 at 09:41:26AM +1200, John Fouhy wrote: > On 04/09/06, Lowell H. Tackett <[EMAIL PROTECTED]> wrote: > > I would like to---so far without luck--to print out my Python scripts with > > syntax highlighting (using Mandrake Linux as my OS/host.) Using enscript > > has > > not gotten me anywhere; nor has a package I found on the *net called > > 'pretty-print', or some such similar to that. > > Well, you could open your code in vim or emacs and click "print"? :-) > > > It occured to me that it ought to be very simple to gain access to those > > syntax discrimnators, write a code script that creates a 'dye' for each > > syntax type, and pipe a print request thru such a file. > > Well, on this windows system, the vim python syntax file is in > Vim\vim70\syntax\python.vim. > > It looks like you could make a reasonable stab at parsing it without > knowing what everything means, especially if you're willing to accept > the odd error. > > I'm not sure how you want to go about colourizing things, though. If > you have a postscript printer, you could generate your own postscript, > maybe.. > The SciTE text editor, which runs on both Linux and MS Windows, will export a Python source code file to HTML, PDF, RTF, LaTeX, and XML. See: http://www.scintilla.org/SciTE.html The export feature is under the File/Export menu item. SciTE also does syntax highlighting/colorizing of Python code. Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does "random" in shuffle( x[, random]) do?
[snip] Ah, I'd forgotten that in shuffle( x[, random], "random" would be the default. But please bear with me. Using your function a, I wrote testShuffle.py: # testShuffle.py from random import * def a(): return 0.5 lst = ['1', '2', '3', '4'] shuffle(lst,a) print lst >>> ['1', '4', '2', '3'] >>> Again, this just the random reordering of lst in place. Could you show me a little script where the 2nd argument of shuffle actually does something?no, it's not a random reordering.As others have said already,you can't determine the randomness of a function just by running it once.Why do you think it's a random reordering? If you ran it many times, you'd see why we've been saying that it's important not to test it just once.#--- example script.pyfrom random import shuffledef a(): return 0.5def run_shuffle(lst): shuffle(lst,a) print lstimport copylst = [1,2,3,4]for x in range(20): tmp = copy.copy(lst) run_shuffle(tmp)#--- endoutput:[1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3] [1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3] [1, 4, 2, 3][1, 4, 2, 3][1, 4, 2, 3]>>> So yes, I have already given you an example where the second argument does something.Or do you still think that it's random? :) Thanks,You're welcome. Dick Moores-Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pretty_printing
On 04/09/06, Lowell H. Tackett <[EMAIL PROTECTED]> wrote: > I would like to---so far without luck--to print out my Python scripts with > syntax highlighting (using Mandrake Linux as my OS/host.) Using enscript has > not gotten me anywhere; nor has a package I found on the *net called > 'pretty-print', or some such similar to that. Well, you could open your code in vim or emacs and click "print"? :-) > It occured to me that it ought to be very simple to gain access to those > syntax discrimnators, write a code script that creates a 'dye' for each > syntax type, and pipe a print request thru such a file. Well, on this windows system, the vim python syntax file is in Vim\vim70\syntax\python.vim. It looks like you could make a reasonable stab at parsing it without knowing what everything means, especially if you're willing to accept the odd error. I'm not sure how you want to go about colourizing things, though. If you have a postscript printer, you could generate your own postscript, maybe.. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] tempfile and webbrowser
Kent Johnson a écrit : > The problem is that the file is never actually written because you omit > the close. But when you do close the temp file, it is deleted. Try using > a.flush() instead of a.close(), that will force the file to be written. > Alternately use tempfile.mkstemp() which lets you close the file and > delete it when you are done with it. Thank you, this works: import tempfile import webbrowser a = tempfile.mkstemp('.html') f= open(a[1],'w') f.write("Test") f.close() webbrowser.open(f.name) * -- Yves Egrix ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does "random" in shuffle( x[, random]) do?
At 04:43 AM 9/3/2006, Kent Johnson wrote: >Dick Moores wrote: > > http://docs.python.org/lib/module-random.html says, > > > > "shuffle( x[, random]) > > Shuffle the sequence x in place. The optional argument random is > a 0-argument > > function returning a random float in [0.0, 1.0); by default, this is the > > function random()." > > > > >>> from random import shuffle, random > > >>> lst = ["a", "b", "c", "d"] > > >>> shuffle(lst) > > >>> lst > > ['c', 'b', 'd', 'a'] > > >>> shuffle(lst, random) > > >>> lst > > ['d', 'c', 'b', 'a'] > > >>> > > > > I can't see that shuffle(a) is any different from shuffle(a, > random). Is it? And > > how? > > >The docs say that shuffle(a) *is* the same as shuffle(a, random). If you >don't supply a second argument, the function random() is used. So >passing random as the second arg is the same as omitting the second arg. > >One reason to provide your own random function would be if you have one >that is more random than the standard function, for example os.urandom() >or a function based on an external random source such as >http://www.fourmilab.ch/hotbits/. The random number generator in Python >(Mersenne twister) is very high quality but that hasn't always been the >case and it is still deterministic. > >You might be interested in the Wikipedia article: >http://en.wikipedia.org/wiki/Random_number_generator >http://en.wikipedia.org/wiki/Mersenne_twister > >Trying the two versions once each, getting different results and saying >you can't see that they are different is...an interesting approach :-) Well, sure it's stupid if you know what "supplying your own random function in place of random.random()" means. I do now, thanks to you and Alan Gauld. >But seriously, even with a poor random function you would have to call >shuffle many times and analyze the entire body of results carefully to >see any problem. Because I'm content with the pseudo-randomness supplied by the current random.random(), I won't pursue my questions about that 2nd argument of shuffle() any longer. Thanks to all, Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does "random" in shuffle( x[, random]) do?
At 01:51 AM 9/3/2006, Luke Paireepinart wrote: On 9/3/06, Dick Moores <[EMAIL PROTECTED]> wrote: http://docs.python.org/lib/module-random.html says, "shuffle( x[, random]) Shuffle the sequence x in place. The optional argument random is a 0-argument function returning a random float in [0.0, 1.0); by default, this is the function random()." it means you can pass in your own random function. for example: def a: return 0.5 shuffle(lst, a) will call the 'a' function instead of using the function called ' random.random', and since 'a' just returns a constant the results won't be random. It's letting you define your own random number-generating function if you want. it just tells you it's 'zero-argument' so you know that shuffle(lst, funcname) results in the call funcname() with no arguments. If your random function required arguments you could probably use lambda somehow to pass the arguments into it. HTHT, -Luke >>> from random import shuffle, random >>> lst = ["a", "b", "c", "d"] >>> shuffle(lst) >>> lst ['c', 'b', 'd', 'a'] >>> shuffle(lst, random) >>> lst ['d', 'c', 'b', 'a'] >>> I can't see that shuffle(a) is any different from shuffle(a, random). Is it? And how? No it's not because using the function 'random.random' is the default :) Ah, I'd forgotten that in shuffle( x[, random], "random" would be the default. But please bear with me. Using your function a, I wrote testShuffle.py: # testShuffle.py from random import * def a(): return 0.5 lst = ['1', '2', '3', '4'] shuffle(lst,a) print lst >>> ['1', '4', '2', '3'] >>> Again, this just the random reordering of lst in place. Could you show me a little script where the 2nd argument of shuffle actually does something? Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] pretty_printing
Hello, folks. These seems as good as another question to take a first plunge into your forum. I would like to---so far without luck--to print out my Python scripts with syntax highlighting (using Mandrake Linux as my OS/host.) Using enscript has not gotten me anywhere; nor has a package I found on the *net called 'pretty-print', or some such similar to that. It had occured to me that the root of my lack of success is simply that file XYZ.py sits on my HD as a simple string of X's and O's, not as a pretty, colorful text repository. Only thru the magic of say, Vim, is the display converted to meaningful hues. Therefor, Vim somehow knows how to detect each of the discrete syntax types: comments, quotes, reserved words, etc., and to apply an appropriate color into its' display. It occured to me that it ought to be very simple to gain access to those syntax discrimnators, write a code script that creates a 'dye' for each syntax type, and pipe a print request thru such a file. Just to put my experience in perspective, I'm about halfway thru Michael Dawson's [wonderful] book "Python Programming for the Absolute Beginner". This concept is jumping way out of my present 'box', and I'm kind of excited that the whole thing occured to me, and anxious to move ahead and experiement with it. Just don't know where to get started. (Yes, I know that there are probably many applications blowing about 'out there', but that's not the point, is it?) -- >From Lowell's computer... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] tempfile and webbrowser
yves wrote: > Hello tutors, > > This programm works: > ** > import webbrowser > a = open('test.htm','wb') > a.write("Test") > webbrowser.open(a.name) > a.close() > *** > but I would like to avoid the risk of overwriting an already existing > "test.htm" file, so I try to use the module tempfile: > *** > import tempfile > import webbrowser > a = tempfile.NamedTemporaryFile('w+b',-1,'.html') > a.write("Test") > webbrowser.open(a.name) > #a.close() > ** > This does not work (no traceback error though): the browser displays a > blank page. The problem is that the file is never actually written because you omit the close. But when you do close the temp file, it is deleted. Try using a.flush() instead of a.close(), that will force the file to be written. Alternately use tempfile.mkstemp() which lets you close the file and delete it when you are done with it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] tempfile and webbrowser
Hello tutors, This programm works: ** import webbrowser a = open('test.htm','wb') a.write("Test") webbrowser.open(a.name) a.close() *** but I would like to avoid the risk of overwriting an already existing "test.htm" file, so I try to use the module tempfile: *** import tempfile import webbrowser a = tempfile.NamedTemporaryFile('w+b',-1,'.html') a.write("Test") webbrowser.open(a.name) #a.close() ** This does not work (no traceback error though): the browser displays a blank page. I am using Python2.3.3 on Windows XP, and Firefox. Have you got some suggestions to tackle this problem? -- Yves Egrix ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about random seed
>> random.seed() sets the starting number for the generator. Setting the >> seed to a known value can be important if you want the same sequence of >> pseudorandom numbers to be generated each time you test/run your >> program. >> > I still can not understand. can you show me an example? Hi Linda, Ok, let's start from basics. Normally, functions give the same results if we pass in the same inputs. If we have a function like: def square(x): return x * x then we really expect 'square(42)' to return the same value as 'square(42)' because the input is the same. But this poses a dilemma: we'd like to have a function that gives us "random" numbers, but we also want to be able to call it using the same (empty) input. That is, we'd like: random.random() to give a different result than another call to: random.random() In the mathematical sense, random.random() isn't a "function", but that's ok, because we programmers play fast and loose with these things anyway. *grin* So how does this work? The idea is to have the random.random() function keep some memory of the last random number that it already returned. That way, when we call random.random() again, it'll have a chance to return something different. The idea looks like: ### _hidden_seed = 0 def my_random(): global _hidden_seed _hidden_seed = _hidden_seed + 1 return _hidden_seed ### I'm putting in the understored '_hidden_seed' global variable that's reused in our calls to my_random(). Now my_random() will give us varying results every time we call it: ## >>> my_random() 1 >>> my_random() 2 >>> my_random() 3 ## But the only problem here, now, is that the results aren't particularly "random" looking. So maybe we can do something a little crazier besides just adding 1 to it: maybe we can do some multiplication, take remainders, ... etc, to scramble the number up. That's the job of a good random number generator. Also notice that there's nothing truly "random" doing on here. The stream of numbers that come out of mutiple calls to my_random() is completely predictable if we know two things: * the initial seeding value * the algorithm used to generate the next value Out of these two, the only thing that's potentially different between Python runs is the seeding value, since the algorithm we use is fixed. When Python starts up, it's initially set to some value that relates to the current time, to further extend the illusion of randomness between program runs. random.seed(), the function you were trying to play with, resets the seed to something you want. So if you want to forcefully generate the same "random" values, set the seed to something hardcoded, and then start calling random.random(). Please feel free to ask more questions about this. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does "random" in shuffle( x[, random]) do?
> "shuffle( x[, random]) > Shuffle the sequence x in place. The optional argument random is a > 0-argument function returning a random float in [0.0, 1.0); by > default, this is the function random()." > from random import shuffle, random lst = ["a", "b", "c", "d"] shuffle(lst) shuffle(lst, random) > > I can't see that shuffle(a) is any different from shuffle(a, > random). Is it? And how? It isn't any different in this case. The docs point out that if you don't provide a value then random is used. So by passing random you are simpoly doing what the default behaviour does. To see anything different try defining your own function that returns a value between 0 and 1: def r0(): return 0 def r1(): return 0.9) Try using those values and see if the amount of randomness in shuffles behaviour changes for f in [r0,r1,random]: print '-' for n in range(3): lst = ['a','b','c','d'] shuffle(lst,f) print lst Can you see how the function has a difference now? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with Pythonwin
> I am using a windows box and I have installed Activestate > ActivePython 2.4 > When I start Pythonwin IDE, it gives me the following error: > > * File "", line 1, in ? > File > "C:\python\Lib\site-packages\pythonwin\pywin\framework\startup.py", > line 49, in ? >exec "import %s\n" % moduleName > File "re.py", line 9, in ? >i = input("Enter any positive integer\n") > exceptions.EOFError: EOF when reading a line* Is this the first time you have started (or tried to start) Pythonwin? Or did it used to work and is now broken? How are you trying to start Pythonwin? Are you running it from the Start Menu? The error you are seeing should only occur if you are starting pythonwin with a commandline argument, and that's unusual! If you have just installed it and this is the first time you've tried running Pythonwin then I'd suggest uninstalling Python, and then reinstalling it. If that still gives the same error check the Pyhonwin shortcutr properties to see if any arguments are being passed to it. Best I can think of... Alan g ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Handling hundreds of thousands of inserts with MySQLdb
Gonzillaaa wrote: > another issue is that some of the fields values are empty and I > get the following : > > ./xbow_MySQL_insert.py:49: Warning: Out of range value adjusted for > column 'sample' at row 64 >cursor.executemany("INSERT INTO arup_04 \ > > is there a way to "silence" python so it doesn't output the errors? Rather than silence the warnings I would fix the data. You could process each row in your returnTuple() function. Alternately you could perhaps change your database table to allow the data. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with Pythonwin
Asrarahmed Kadri wrote: > Hi folks, > > > I am new to Python and have just taken a few steps in this long journey.. > > I am using a windows box and I have installed Activestate ActivePython 2.4 > > When I start Pythonwin IDE, it gives me the following error: > > File "re.py", line 9, in ? > i = input("Enter any positive integer\n") > exceptions.EOFError: EOF when reading a line* > You have a file re.py in the python path that is shadowing the library module re. Rename your file to something else and try again. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What does "random" in shuffle( x[, random]) do?
Dick Moores wrote: > http://docs.python.org/lib/module-random.html says, > > "shuffle( x[, random]) > Shuffle the sequence x in place. The optional argument random is a 0-argument > function returning a random float in [0.0, 1.0); by default, this is the > function random()." > > >>> from random import shuffle, random > >>> lst = ["a", "b", "c", "d"] > >>> shuffle(lst) > >>> lst > ['c', 'b', 'd', 'a'] > >>> shuffle(lst, random) > >>> lst > ['d', 'c', 'b', 'a'] > >>> > > I can't see that shuffle(a) is any different from shuffle(a, random). Is it? > And > how? > The docs say that shuffle(a) *is* the same as shuffle(a, random). If you don't supply a second argument, the function random() is used. So passing random as the second arg is the same as omitting the second arg. One reason to provide your own random function would be if you have one that is more random than the standard function, for example os.urandom() or a function based on an external random source such as http://www.fourmilab.ch/hotbits/. The random number generator in Python (Mersenne twister) is very high quality but that hasn't always been the case and it is still deterministic. You might be interested in the Wikipedia article: http://en.wikipedia.org/wiki/Random_number_generator http://en.wikipedia.org/wiki/Mersenne_twister Trying the two versions once each, getting different results and saying you can't see that they are different is...an interesting approach :-) But seriously, even with a poor random function you would have to call shuffle many times and analyze the entire body of results carefully to see any problem. Kent > Thanks, > > Dick Moores > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with Pythonwin
It is very hard to know what caused that, but could you post the piece of code you were trying to execute?? Or did you get the error when you opened the Pythonwin without any code?? -- Dominik - Original Message - From: Asrarahmed Kadri To: tutor@python.org Sent: Sunday, September 03, 2006 10:34 AM Subject: [Tutor] Problem with Pythonwin Hi folks, I am new to Python and have just taken a few steps in this long journey.. I am using a windows box and I have installed Activestate ActivePython 2.4 When I start Pythonwin IDE, it gives me the following error: File "", line 1, in ? File "C:\python\Lib\site-packages\pythonwin\pywin\framework\startup.py", line 49, in ? exec "import %s\n" % moduleName File "", line 1, in ? File "C:\python\Lib\site-packages\pythonwin\pywin\framework\intpyapp.py", line 8, in ? import string File "C:\python\Lib\string.py", line 83, in ? import re as _re File "re.py", line 9, in ? i = input("Enter any positive integer\n")exceptions.EOFError: EOF when reading a line Can anyone help me with this?? Regards, Asrar ___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Handling hundreds of thousands of inserts with MySQLdb
On 2 Sep 2006, [EMAIL PROTECTED] wrote: > > Hello all. I post this here since is my first attempt to solve a > problem with python. > > I have fairly big log files that I'm doing some pre-processing to, to > cleanup the data before they go into a MySQL database. After > processing the files look something like this: > > 17, , 2006-8-21 12:04:29, 0, 3.0846, 25.105, 918, -0.12183, 0.20305, > 25.389, 25.254, 180 > 18, , 2006-8-21 12:05:20, 17, 3.1705, 23.62, 949, 0.015228, 0.040609, > 24.984, 110.2, 186 > 17, , 2006-8-21 12:07:30, 0, 3.0846, 25.353, 939, -0.1269, 0.20305, > 25.254, 25.254, 293 > 18, , 2006-8-21 12:08:23, 17, 3.1705, 23.538, 958, 0.015228, > 0.045685, 24.984, 110.2, 188 > 16, , 2006-8-21 12:09:21, 17, 3.0922, 24.691, 969, 0.26904, 0.10152, > 25.389, 25.389, 175 > > then I have written another script to which I pass the filename as > argument to insert that data into the db. The problem I'm getting is > that some of the files contain 30 records aprox. I have tried two > approaches to inset the data but both have failed I would recommend a third approach: use "LOAD DATA INFILE" from MySql. You can find its syntax e.g here: http://dev.mysql.com/doc/refman/5.0/en/load-data.html That is very fast and you need only one statement. You could also use mysqlimport from the commandline to import the data. If you want to insert the data with INSERT statements I would read the data file line by line and insert that data. That is simple not as fast as LOAD DATA INFILE but for most situations fast enough. Then you shouldn't have the problem with max_allowed_packet (you can increase its value if you need to; for MySql 5.0 its maximum value is 1GB IIRC. If you need speed use mysqlimport from the commandline or LOAD DATA INFILE; insert statements even with multiple values will never be as fast as that. Karl -- Please do *not* send copies of replies to me. I read the list ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problem with Pythonwin
Hi folks, I am new to Python and have just taken a few steps in this long journey.. I am using a windows box and I have installed Activestate ActivePython 2.4 When I start Pythonwin IDE, it gives me the following error: File "", line 1, in ? File "C:\python\Lib\site-packages\pythonwin\pywin\framework\startup.py", line 49, in ? exec "import %s\n" % moduleName File "", line 1, in ? File "C:\python\Lib\site-packages\pythonwin\pywin\framework\intpyapp.py", line 8, in ? import string File "C:\python\Lib\string.py", line 83, in ? import re as _re File "re.py", line 9, in ? i = input("Enter any positive integer\n")exceptions.EOFError: EOF when reading a line Can anyone help me with this?? Regards, Asrar ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about random seed
linda.s schreef: > I still can not understand. can you show me an example? > Thanks! > Linda Example program: import random random.seed(42) for i in range(10): print random.random() At the start of the program, the random number generator is seeded with 42. This could be any number, but the point is that it doesn't change when you run the program again. As a result, the output is the same every time you run the program. If you choose a different seed, you get different results from random.random(). If you don't use random.seed(), the random module uses the current time as the seed. Since the current time always changes, the program will generate different output each time it runs. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] What does "random" in shuffle( x[, random]) do?
http://docs.python.org/lib/module-random.html says, "shuffle( x[, random]) Shuffle the sequence x in place. The optional argument random is a 0-argument function returning a random float in [0.0, 1.0); by default, this is the function random()." >>> from random import shuffle, random >>> lst = ["a", "b", "c", "d"] >>> shuffle(lst) >>> lst ['c', 'b', 'd', 'a'] >>> shuffle(lst, random) >>> lst ['d', 'c', 'b', 'a'] >>> I can't see that shuffle(a) is any different from shuffle(a, random). Is it? And how? Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor