Re: Which SQL module to use?
I'm using MySQLdb. I use a FREE MySQL server at freesql.org. I also have an example class and some functions that use the module. even a simple script that turns a .cvs into a mysql table. contact me if interested. -edward -- http://mail.python.org/mailman/listinfo/python-list
testing for modules?
i have a generic script that is using several modules on windows and linux boxes. i need to have the scripts test if a module is installed, and then if not - then to install the module. can anyone give me a headsup on how to test for a module, returning something to indicate whether or not it is installed, then after that executing file to install the module.? just somewhere to start would be helpful! thanks in advance. -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: WTF?
happens to me too. -- http://mail.python.org/mailman/listinfo/python-list
MySQL & Python
Just migrating now from ASP/to MySQL and Python. I am trying to create a simple script to access a MySQL DB. The Module for MySQL looks very easy, however I do not understand one thing ... In ASP, you can just create a new DB with Access. In MySQL, how do I create a database to start playing with? I see all of the commands to edits tables and values and move a cursor, but I do not see how I actually create THE INITIAL DB, any help would be appreciated. thanks. -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
encryption with python?
What's the best module for encryption with python, anyone out there using python and encryption together?-- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
My First Python Script
So I have a script, first part of a script that I am making to determine each possible combination of IP addresses that are out there. This part is just to get the end of the IP (the last 3 digits). So, they are from 0 - 255. I just want to print 0 - 255, HOWEVER If the number is only say ... 3, then I want mySet to be 003, not 3. I need to add the zeros to the front. My code is below - I guess that there is something to do with my variable types etc. I am not used to the way that Python handles variable types so I am kind of lost, can anyone help ... # Script to Evaluate every possible IP Address Combo # 9/15/05 def ZeroThrough255(): x = 0 while x <= 255: if len(x) == 1: mySet = '00' + str(x) elif len(x) == 2: mySet = '0' + str(x) else: mySet = x print mySet x +=1 ZeroThrough255() The file is also attached.-- edward hotchkiss # Script to Evaluate every possible IP Address Combo # 9/15/05 def ZeroThrough255(): x = 0 while x <= 255: if len(x) == 1: mySet = '00' + str(x) elif len(x) == 2: mySet = '0' + str(x) else: mySet = x print mySet x +=1 ZeroThrough255() -- http://mail.python.org/mailman/listinfo/python-list
Re: My First Python Script
But then I still get the error with the len(x) statement .. hmm On 9/15/05, James Stroud <[EMAIL PROTECTED]> wrote: Try the % operator with strings.For instance: "%03.d" % 5py> "%03.d" % 5 '005'This operator, from what I have experienced, has the same properties as theunix printf. In python, I think its called "string formatting".JamesOn Thursday 15 September 2005 20:33, Ed Hotchkiss wrote: > So I have a script, first part of a script that I am making to determine> each possible combination of IP addresses that are out there.> This part is just to get the end of the IP (the last 3 digits). So, they > are from 0 - 255. I just want to print 0 - 255, HOWEVER> If the number is only say ... 3, then I want mySet to be 003, not 3. I> need to add the zeros to the front.> My code is below - I guess that there is something to do with my variable > types etc. I am not used to the way that Python handles variable types so I> am kind of lost, can anyone help ...>> # Script to Evaluate every possible IP Address Combo>> # 9/15/05 >> def ZeroThrough255():>> x = 0>> while x <= 255:>> if len(x) == 1:>> mySet = '00' + str(x)>> elif len(x) == 2:>> mySet = '0' + str(x) >> else:>> mySet = x>> print mySet>> x +=1>> ZeroThrough255()>> > The file is also attached.--James Stroud UCLA-DOE Institute for Genomics and ProteomicsBox 951570Los Angeles, CA 90095http://www.jamesstroud.com/-- http://mail.python.org/mailman/listinfo/python-list-- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a database. Sugestions?
Is this for running an SQL database, then using a separate python module to access the database? On 15 Sep 2005 21:31:27 -0700, gsteff <[EMAIL PROTECTED]> wrote: SQLite rocks, its definitely the way to go. Its binary is around 250K,but it supports more of the SQL standard than MySQL. It CAN be thread safe, but you have to compile it with a threadsafe macro enabled..check out www.sqlite.org for more info. The windows binariesapparently are compiled with this option, but the Linux binaries are not, so if you're on Linux, you'll have to compile it yourself, whichisn't hard.--http://mail.python.org/mailman/listinfo/python-list -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: encryption with python?
Awesome. I just started Python today so I'd have no idea ... how good is this encryption compared to PGP? Any info on using this file? Didn't see any on this guys site ... On 9/16/05, Robert Kern <[EMAIL PROTECTED]> wrote: Ed Hotchkiss wrote:> Gmail was just an example, I just wanted to learn to play with it ...> I mean the thrill of seeing a file that MY script encrypted hehe... Again, keep it on the list, not private email, please.Probably the simplest encryption module would be Paul Rubin's p3.py . Itonly requires the standard library. http://www.nightsong.com/phr/crypto/p3.py--Robert Kern[EMAIL PROTECTED]"In the fields of hell where the grass grows highAre the graves of dreams allowed to die." -- Richard Harter-- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: My First Python Script
Sweet, time to play with python for a whole day today :P On 9/16/05, Gary Wilson Jr <[EMAIL PROTECTED]> wrote: Ed Hotchkiss wrote:> def ZeroThrough255():> x = 0> while x <= 255: > if len(x) == 1:> mySet = '00' + str(x)> elif len(x) == 2:> mySet = '0' + str(x)> else:> mySet = x > print mySet> x +=1>> ZeroThrough255()Instead of using the while loop and a counter, you can use the range()function. Using range() and string formatting you could to something like: def ZeroThrough255(): for num in range(256): print "%03d" % numwhich, using a list comprehension and the string join() function, could alsobe written as:def ZeroThrough255(): print "\n".join(["%03d" % num for num in range(256)])--http://mail.python.org/mailman/listinfo/python-list -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a database. Sugestions?
Awesome, I'm checking both out right now, trying to get it setup - thanks. On 9/16/05, Christoph Haas <[EMAIL PROTECTED]> wrote: On Thu, Sep 15, 2005 at 11:00:46PM +0200, ionel wrote:> I'm looking for a thread-safe database. > Preferably an embedded, sql database.>> What are the best choices in terms of speed ?Sqlite may be a good choice. It doesn't have network overhead, operateson simple files on the disk (nothing to configure) and is often faster than MySQL & Co.RegardsChristoph--~~~".signature" [Modified] 3 lines --100%--3,41 All-- http://mail.python.org/mailman/listinfo/python-list-- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a database. Sugestions?
So I opted actually to stick with MySQL since I got hooked up with a DB free and It's more of a standard. I'm looking at documentation, and wondering why not just use _mysql which is built in, versus the MySQLdb module? I don't get this ... -edward -- http://mail.python.org/mailman/listinfo/python-list
First Script Problem
This script should just be writing every possibly IP (yea, there are billions i know blah blah) to a txt file. Instead of just writing the IP, it continues and the number goes past 4 groups. IE: The possible IP keeps getting 3 characters longer every time. And at the end of the last loops do I somehow have to set my mySet to NULL? Any ideas here? -- edward hotchkiss # Script to Evaluate every possible IP Address Combo, then write it to a text file# 9/15/05 # ipFileLocation = r"G:\Python\myCode\IPList.txt" ipFileLocation = "IPList.txt"ipFile = open(ipFileLocation, 'w') def findIPs(): for num in range(256): mySet = "%03.d" % num for num in range(256): mySet = mySet + "." + "%03.d" % num for num in range(256):mySet = mySet + "." + "%03.d" % num for num in range(256): mySet = mySet + "." + "%03.d" % num ipFile.write(mySet+"\n") findIPs() ipFile.close() # Script to Evaluate every possible IP Address Combo, then write it to a text file # 9/15/05 # ipFileLocation = r"G:\Python\myCode\IPList.txt" ipFileLocation = "IPList.txt" ipFile = open(ipFileLocation, 'w') def findIPs(): for num in range(256): mySet = "%03.d" % num for num in range(256): mySet = mySet + "." + "%03.d" % num for num in range(256): mySet = mySet + "." + "%03.d" % num for num in range(256): mySet = mySet + "." + "%03.d" % num ipFile.write(mySet+"\n") findIPs() ipFile.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: My First Python Script
Someone else actually got me some help, the end result he hooked me up with was: # function to evaluate all possible IPs def findIPs(): ipFile = open("IPList.txt", 'w') for octet1 in range(256): for octet2 in range(256): for octet3 in range(256): for octet4 in range(256): ipAddress = '%03.d.%03.d.%03.d.%03.d\n' % (octet1, octet2,octet3, octet4) ipFile.write(ipAddress) ipFile.close() # execute the function findIPs()Thanks though, your response helps me understand variables better now.. On 9/16/05, John Hazen <[EMAIL PROTECTED]> wrote: * Ed Hotchkiss <[EMAIL PROTECTED]> [2005-09-15 20:36]: > But then I still get the error with the len(x) statement .. hmmAhh. In the future, it will help us help you, if you make it clear thatthere was an error, and *paste the exact error* into your mail. For example, I'm guessing the error you got is:>>> len(255)Traceback (most recent call last):File "", line 1, in ?TypeError: len() of unsized objectAs Robert said, this is because integers don't have a length. James' suggestion to use string formatting is probably the "best"solution, but the formatting codes are fairly daunting for someone neverexposed to them.> if len(x) == 1:> mySet = '00' + str(x) > elif len(x) == 2:> mySet = '0' + str(x)You know intuitively that strings *do* have length, and you appear toknow how to create a string from an integer. So the easiestmodification to your code to make it work wolud be something like: mySet = str(x)if len(mySet) == 1: mySet = '00' + mySetelif len(mySet) == 2: mySet = '0' + mySetNow, this can be made a little more elegant (and generalized) by usingthe algorithm "if the string is too short, keep prepending zeros until it's long enough."target_length = 3mySet = str(x)while len(mySet) < target_length: mySet = '0' + mySetBut this isn't as efficient as your solution. Once you know about theinteresting ability to multiply strings ("0" * 3 = "000"), you can create a solution that's general, elegant, and efficient:target_length = 3mySet = str(x)mySet = '0' * (target_length - len(mySet)) + mySetHTH-John -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting tuple from text file into database fields
So I changed the code a little, still throwing the SQL syntax error. I still cannot seem to identify the problem. # Script to add links from a comma deliminated file to a MySQL database# 9/16/05 import MySQLdb conn=MySQLdb.connect( host="www.freesql.org", user="edhotchkiss", port=3306, passwd="test1", db="links") cursor = conn.cursor()stmt = "DROP TABLE IF EXISTS links"cursor.execute(stmt)stmt = """CREATE TABLE links ( ID INT NOT NULL, Name TEXT, URL LONGTEXT, Category LONGTEXT, primary key (ID))"""cursor.execute(stmt) arr=[]inp = open ("sites1.txt","r")#read line into arrayfor line in inp.readlines(): links = map(str, line.split(",")) arr.append(links) cursor.execute (""" INSERT INTO links (Name, URL, category) VALUES (%s, %s, %s) % tuple(links[0:3]) """)cursor.close()conn.close() -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb error - PLEASE SAVE ME!
Ok. I am trying to read a csv file with three strings separated by commas. I am trying to insert them into a MySQL DB online. MySQLdb is installed, no problems. I think that I am having some kind of error with my csv going into the fields and being broken apart correctly. Can someone please help? I attached the code below, it does work with that SQL server also if you want to try and run it. Thanks in advance .. - # Script to add links from a comma deliminated file to a MySQL database # 9/16/05 import MySQLdb conn=MySQLdb.connect( host="www.freesql.org", user="edhotchkiss", port=3306, passwd="test1", db="links") cursor = conn.cursor() stmt = "DROP TABLE IF EXISTS links" cursor.execute(stmt) stmt = """CREATE TABLE links ( ID INT NOT NULL, Name TEXT, URL LONGTEXT, Category LONGTEXT, primary key (ID) )""" cursor.execute(stmt) arr=[] inp = open ("sites1.txt","r") #read line into array for line in inp.readlines(): links = map(str, line.split(",")) arr.append(links) cursor.execute (""" INSERT INTO links (Name, URL, category) VALUES (%s, %s, %s)""" % tuple(links[0:3]) ) cursor.close() conn.close() -- edward hotchkiss -- edward hotchkiss # Script to add links from a comma deliminated file to a MySQL database # 9/16/05 import MySQLdb conn=MySQLdb.connect( host="www.freesql.org", user="edhotchkiss", port=3306, passwd="test1", db="links") cursor = conn.cursor() stmt = "DROP TABLE IF EXISTS links" cursor.execute(stmt) stmt = """CREATE TABLE links ( ID INT NOT NULL, Name TEXT, URL LONGTEXT, Category LONGTEXT, primary key (ID) )""" cursor.execute(stmt) arr=[] inp = open ("sites1.txt","r") #read line into array for line in inp.readlines(): links = map(str, line.split(",")) arr.append(links) cursor.execute (""" INSERT INTO links (Name, URL, category) VALUES (%s, %s, %s)""" % tuple(links[0:3]) ) cursor.close() conn.close() O'reilly Python Archive,http://python.oreilly.com/archive.html,python Python Tutorials,http://www.awaretek.com/tutorials.html,python MySQL Python,http://sourceforge.net/projects/mysql-python,python Python Vaults of Parnassus,http://www.vex.net/parnassus/,python PyCrypto,http://www.amk.ca/python/code/crypto,Python-- http://mail.python.org/mailman/listinfo/python-list
Best Encryption for Python Client/Server
Let us say that I am trying to create a very small and simple private network/connection between several scripts on different machines, to communicate instructions/data/files etc. to each other over the net. Is SSL the best method? Any recommendations of something to get started with? Thanks in advance. -- Edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Best Encryption for Python Client/Server
Let us say that I am trying to create a very small and simple private network/connection between several scripts on different machines, to communicate instructions/data/files etc. to each other over the net. Is SSL the best method? Any recommendations of something to get started with? Thanks in advance. -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
Let us say that I am trying to create a very small and simple private network/connection between several scripts on different machines, to communicate instructions/data/files etc. to each other over the net. Is SSL the best method? Any recommendations of something to get started with? Thanks in advance. -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
tuples and mysqldb tables
I have used fetchall() to insert the values from a table into a tuple. anywhere from 0 - ? many rows could be in this tuple, so it is a row within a row. How do I use a loops to iterate through the nested tuple, and assign the tuples integers and strings to variables, ugh :P The Tables data is like this: +-+ | ID (INT) | Protocol (TEXT) | Name (LONGTEXT) Description (LONGTEXT) | +-+ import MySQLdb import sys # find out what this ports function is def grabPortInfo(port): try: conn=MySQLdb.connect( host="www.freesql.org", user="portnumbers", port=3306, passwd="*", db="portnumbers") except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) print "\n\n WTF!? - portnumbers MySQL DB didn't open" sys.exit (1) # -- cursor = conn.cursor() stmt = "SELECT * FROM portnumbers WHERE port=%i" %port cursor.execute(stmt) numrows = int(cursor.rowcount) if numrows == 0: print "port # not found in database" elif numrows >= 1: result = cursor.fetchall() print len(result) # break tuple into strings with output myPort = port myProtocol = result[0|3] myName = result[0|4] myDescription = result[0|5] print "PORT # | PROTOCOL | PORT NAME | PORT DESCRIPTION " print myPort, myProtocol, myName, myDescription cursor.close() conn.close() # end function - grabPortInfo(22) -- http://mail.python.org/mailman/listinfo/python-list
Re: threads/sockets quick question.
Well, I fixed those problems, now what I have is this: but i am getting errors with the global variables or something ... am i supposed to use this class and def together differently? I just don't seem to understand ... -edward import socketimport threadingimport traceback class scanThread(threading.Thread): def run(self): try: ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ss.connect((ip, port_counter)) print "%s | %d OPEN" % (ip, port_counter) ss.close() print "scanned: ",port_counter,"\n" except: traceback.print_exc()# end class --- def scan(ip, thebegin, theend): global ip global thebegin global theend port_counter = 0 for port_counter in range(thebegin, theend): scanThread().start() # end function ---scan("localhost", 0, 1) -- http://mail.python.org/mailman/listinfo/python-list
Re: threads/sockets quick question.
Let's say that I avoid the complexities of using classes, and that I avoid using anything to count the threads... import socketimport threading def scan(ip, port): try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((ip, port)) s.close() print '%s | %d OPEN \nscanned: %d' % (ip, port, port) except: print '%s | %d CLOSED \nscanned: %d' % (ip, port, port) ip = 'localhost'for port in range(1, 1024): thread.start_new_thread(scan, (ip, port,)) Why does this produce the errr - can't start new thread? I just scrapped the rest of the code before, followed peoples ideas, and removed the complexities, I can learn the rest later I guess... thanks again. -edward -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Encryption for Python Client/Server
Is SSL something which needs a script to register (and pay for) a certificate, or is it just another form of encryption ... also - is there a free implementation of OpenSSL for windows, and is openSSL a default application with *NIX? Thanks. On 9/19/05, James Stroud <[EMAIL PROTECTED]> wrote: SSH can be used for functionality like this, through tunneling. You can eventunnel interprocess communication through SSH. Its not exceptionally complicated.On Sunday 18 September 2005 13:36, Ed Hotchkiss wrote:> Let us say that I am trying to create a very small and simple private> network/connection between several scripts on different machines, to > communicate instructions/data/files etc. to each other over the net. Is SSL> the best method? Any recommendations of something to get started with?> Thanks in advance.--James StroudUCLA-DOE Institute for Genomics and Proteomics Box 951570Los Angeles, CA 90095http://www.jamesstroud.com/--http://mail.python.org/mailman/listinfo/python-list -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Encryption for Python Client/Server
I apologize for misreading your H my dear professor. Perhaps you can google:asshole and see if your image is present, I would highly doubt that it is not within the first page of results. I'm sorry that I did not see the message in the thread which recommended SSH rather than SSL. There is no need to be a dick. - Luckily you were never my professor -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Encryption for Python Client/Server
No worries, I apologize for my outburst. I will check out the viability of using an SSH module, or using pyCrypto or something to encrypt the data. Here's my mission: simple P2P class with encryption of whatever type of file is being sent, and authentication via encrypted user name/password. So any type of file or login being sent over the net, any communication between the scripts should be encrypted, regardless of whether it is client/server communication, or file transfer. Now that I've finally stated what I want to do (sorry) Is SSH a good option, or just using sockets with pycrypto? Thanks in advance. -edward -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Encryption for Python Client/Server
hah :P awesome, I will be busy this week! -edward On 20 Sep 2005 14:23:10 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: Steve Holden <[EMAIL PROTECTED]> writes:> > Here's my mission: simple P2P class with encryption of whatever type > > of file is being sent, and authentication via encrypted user> > name/password. So any type of file or login being sent over the net,> > any communication between the scripts should be encrypted, > > regardless of whether it is client/server communication, or file> > transfer.> Robert's suggestion was a good one, as ssh (rather than SSH) is very> good at building encrypted tunnels between arbitrary processes. If you want to use SSL in a similar fashion, try stunnel(http://www.stunnel.org). Frankly I've never understood why ssh evenexists, but it's very widespread by now, and works pretty well within its limitations.--http://mail.python.org/mailman/listinfo/python-list-- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
please feed the trolls. On 9/21/05, Steve Holden <[EMAIL PROTECTED]> wrote: Rudy Schockaert wrote:>> >> • Do think clearly before writing. >> >> You should start thinking before you write something. Do you really> think anyone takes you serious the way you talk?> I haven't seen anything constructive yet from your side. You always have > to comment, why don't you start writing documentation yourself if it> bothers you so much. Write it the way you think it should be written and> show the rest of the community you are capable of doing anything else > but fucking qwasting others peoples time.1. Do not feed the trolls.2. I offered $100 for a rewrite of the "re" documentation if he couldpersuade 5 regular readers of c.l.py to tell me his version wassuperior. Emails received: 0. 'Nuff said :-)regardsSteve--Steve Holden +44 150 684 7255 +1 800 494 3119Holden Web LLC www.holdenweb.comPyCon TX 2006 www.pycon.org--http://mail.python.org/mailman/listinfo/python-list -- edward hotchkiss -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
I'm new to Python, not programming. I agree with the point regarding the interpreter. what is that? who uses that!? Why are most examples like that, rather than executed as .py files? Another problem that I have (which does get annoying after awhile), is not using foo and bar. Spam and Eggs sucks. It's not funny, although Monty Python does rock. Why not use silly+walks instead. ***/me puts on Monty Python and turns the computer off*** -edward -- http://mail.python.org/mailman/listinfo/python-list