PythonWin: Change background color
Does anyone know of a way to change the background color of the PythonWin windows from the blinding white, to another color, like the way MS Word will allow a dark blue background with white text? I know you can specify colors for all the different style of text via View/Options/Format, but I see nothing for the window itself. Kevin Bell -- http://mail.python.org/mailman/listinfo/python-list
change a value to NULL?
I'm pulling a list of numbers from MS Excel, but occasionally if there is no data from excel, the value is an asterisk, but I need to make it null. What is the best way to do that? Thus far, I'm using: for value in myRange: try: intV = int(value) print intV except: print "its an asterisk" but I need to get at my list and substitute the *'s with nulls to load into a database. Thanks. Kevin Bell -- http://mail.python.org/mailman/listinfo/python-list
RE: change a value to NULL?
Thanks, being new to this, I wasn't sure if I should use None, Null, Nope, Nada, or Nil! I'm going to be loading a list into an MS Access db. Do you know if I load None into an Access field if Access will recognize that as blank/null? I suppose I'll just go test it out. Thanks again... Kevin Bell -Original Message- From: Laszlo Zsolt Nagy [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 05, 2005 10:18 AM To: Bell, Kevin; python-list@python.org Subject: Re: change a value to NULL? Bell, Kevin wrote: >I'm pulling a list of numbers from MS Excel, but occasionally if there >is no data from excel, the value is an asterisk, but I need to make it >null. > >What is the best way to do that? Thus far, I'm using: > > >for value in myRange: > try: > intV = int(value) > print intV > except: > print "its an asterisk" > > I'm affraid I did not understand what is your real problem. Here is an answer, anyway. When converting a string intoto an int, you should use TypeError to trap type errors only: try: intV = int(value) except TypeError: intV = None print intV # It will be None if 'value' is not an int Best, Les -- http://mail.python.org/mailman/listinfo/python-list
RE: change a value to NULL?
Just tested it. Access does recognize None as null/blank/etc when None is passed in from python. Kevin Bell -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bell, Kevin Sent: Wednesday, October 05, 2005 10:33 AM To: python-list@python.org Subject: RE: change a value to NULL? Thanks, being new to this, I wasn't sure if I should use None, Null, Nope, Nada, or Nil! I'm going to be loading a list into an MS Access db. Do you know if I load None into an Access field if Access will recognize that as blank/null? I suppose I'll just go test it out. Thanks again... Kevin Bell -Original Message- From: Laszlo Zsolt Nagy [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 05, 2005 10:18 AM To: Bell, Kevin; python-list@python.org Subject: Re: change a value to NULL? Bell, Kevin wrote: >I'm pulling a list of numbers from MS Excel, but occasionally if there >is no data from excel, the value is an asterisk, but I need to make it >null. > >What is the best way to do that? Thus far, I'm using: > > >for value in myRange: > try: > intV = int(value) > print intV > except: > print "its an asterisk" > > I'm affraid I did not understand what is your real problem. Here is an answer, anyway. When converting a string intoto an int, you should use TypeError to trap type errors only: try: intV = int(value) except TypeError: intV = None print intV # It will be None if 'value' is not an int Best, Les -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: So far
I like pythonWin other than the white background where you write your scripts, because after awhile it's bad on the eyes. Does anyone know of a free IDE that will allow control of this, as well as the coloring of keywords, etc? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christophe Sent: Thursday, October 06, 2005 9:50 AM To: python-list@python.org Subject: Re: So far CppNewB a écrit : > I am absolutely loving my experience with Python. Even vs. Ruby, the syntax > feels very clean with an emphasis on simplification. > > My only complaint is that there doesn't appear to be a great commercial IDE > for the language. I've tried Komodo, etc and they are nice applications, > but they don't feel like they give me the "power" like a Visual Studio or > Delphi (I wish I could articulate better the differences).Finding a > descent GUI builder has been a challenge as well. Most of them have support > for Dialogs, but what about more complex UI's? I may need a resizable frame > within a resizable frame? I haven''t found a GUI builder with a great feel > yet. > > Other than that, my experience has been wonderful. Even after my > complaints, I plan on sticking with Python for a while. Try PyQT with eric3 as an IDE. http://www.die-offenbachs.de/detlev/eric3.html -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
date reformatting
Anyone aware of existing code to turn a date string "8-15-05" into the number 20050815? The dateutil module has a parse method that looks perfect, I downloaded and unzipped it, but could figure out how to install it. I using windows XP and py2.4. Any ideas? Kev -- http://mail.python.org/mailman/listinfo/python-list
interactive window vs. script: inconsistent behavior
The following works in the interactive window of PythonWin, but fails in a script. TypeError: Objects of type 'slice' can not be converted to a COM VARIANT I just need to parse out these dates, but it's making me crazy. Shouldn't it work in both the interactive window and a script? >>> d = "5-18-05 to 5-31-05" >>> print d[0:d.find("to")-1] 5-18-05 >>> print d[d.find("to")+3:] 5-31-05 >>> Kev -- http://mail.python.org/mailman/listinfo/python-list
RE: interactive window vs. script: inconsistent behavior
Oops! Sorry about that post. I'm pulling data from excel, and needed to convert the object I pulled into a string before slicing. I guess I should look (more thoroughly) before I leap. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bell, Kevin Sent: Thursday, October 06, 2005 2:44 PM To: python-list@python.org Subject: interactive window vs. script: inconsistent behavior The following works in the interactive window of PythonWin, but fails in a script. TypeError: Objects of type 'slice' can not be converted to a COM VARIANT I just need to parse out these dates, but it's making me crazy. Shouldn't it work in both the interactive window and a script? >>> d = "5-18-05 to 5-31-05" >>> print d[0:d.find("to")-1] 5-18-05 >>> print d[d.find("to")+3:] 5-31-05 >>> Kev -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Listen for directory events
Anyone have any advice on listening for directory events? I'd like to fire off my script if new files are added to a directory. Right now, I've set up my script as a scheduled task (Windows XP) and when the script is run periodically, it initially looks for new files and does it's magic if there are some. I assume I could have python check for new files then sleep for a bit, and check again. If I did it that way, would I run into problems running other py scripts while the first one was active? I read about processes being protected from each other, but didn't really grok it in fullness. Kev -- http://mail.python.org/mailman/listinfo/python-list
get a copy of a string leaving original intact
I'm having trouble with something that seems like it should be simple. I need to copy a file, say "abc-1.tif" to another directory, but if it's in there already, I need to transfer it named "abc-2.tif" but I'm going about it all wrong. Here's what doesn't work: (I'll add the copy stuff from shutil after figuring out the basic string manipulation.) import os source = r"C:\Source" target = r"P:\Target" files = os.listdir(source) for f in files: if os.path.isfile(target + "\\" + f): # if it already exists print f + " exists" s = f # i'd like a copy to alter s = s.replace("-1", "-2") print "Altered it to be " + s print source + "\\" + s, target + "\\" + s else: print f + " IS NOT THERE YET" print source + "\\" + f, target + "\\" + f # use the original -- http://mail.python.org/mailman/listinfo/python-list
RE: get a copy of a string leaving original intact
I ended up slicing my string into a new one, rather than trying to have a copy of the string to alter in one case, or leave intact in another case. Thanks for the pointer on concatenating paths! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fredrik Lundh Sent: Friday, October 21, 2005 2:10 AM To: python-list@python.org Subject: Re: get a copy of a string leaving original intact "Bell, Kevin" wrote: > I'm having trouble with something that seems like it should be simple. > > I need to copy a file, say "abc-1.tif" to another directory, but if it's > in there already, I need to transfer it named "abc-2.tif" but I'm going > about it all wrong. > > Here's what doesn't work: (I'll add the copy stuff from shutil after > figuring out the basic string manipulation.) define "doesn't work". > import os > > source = r"C:\Source" > target = r"P:\Target" > > files = os.listdir(source) > > for f in files: > if os.path.isfile(target + "\\" + f): # if it already exists > print f + " exists" > s = f # i'd like a copy to > alter > s = s.replace("-1", "-2") > print "Altered it to be " + s > print source + "\\" + s, target + "\\" + s did you mean print source + "\\" + f, target + "\\" + s ? > else: > print f + " IS NOT THERE YET" > print source + "\\" + f, target + "\\" + f # use the original > > -- > http://mail.python.org/mailman/listinfo/python-list btw, note that source + "\\" + f is better written as os.path.join(source, f) e.g. for f in os.listdir(source): sourcefile = os.path.join(source, f) targetfile = os.path.join(target, f) if os.path.isfile(targetfile): targetfile = os.path.join(target, f.replace("-1", "-2")) print "copy", sourcefile, "to", targetfile shutil.copy(sourcefile, targetfile) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
where to download md5.py?
I've been looking around, but haven't found a place to download the md5.py module. I need it to run the dupinator.py Anyone know where to find it? Kev -- http://mail.python.org/mailman/listinfo/python-list
RE: where to download md5.py?
"Bell, Kevin" wrote: > I've been looking around, but haven't found a place to download the > md5.py module. I need it to run the dupinator.py Fredick replied: md5 is a standard Python module (written in C). it's been in Python since the early ages, so if you don't have it, your install is most likely broken (per- haps intentionally, based on this: http://eprint.iacr.org/2004/199 ) if the dupinator you're talking about is this script: http://svn.red-bean.com/bbum/trunk/hacques/dupinator.py you can probably make it work by replacing all references to the "md5" module with "sha". (if that module isn't available either, it's time to talk to your system administrators) That article was s far over my head that I laughed out loud. I don't have sha either, but my system administrators don't know a thing about python. How would they block it? That is the dupinator that I'm talking about. Where would md5 and sha be if they were there? C:\Python24\Lib? I've got md5sum. -- http://mail.python.org/mailman/listinfo/python-list
RE: where to download md5.py?
I guess I do have it. I was looking in LIB for it, because that's where I've typically imported other modules from, like os, etc... >> import md5 >> help(md5) Gives me the help like you'd expect. I was getting an error in the dupinator that I mistakenly attributed to not being able to see md5 in the LIB. Thanks for all of your help. I'll go track down the error now that I know that I'm not just missing a module. -- http://mail.python.org/mailman/listinfo/python-list
convert COM obj to integer
I'm pulling a range of cells from Excel into a list and the data in Excel is a number or possibly some text like an asterisk. Each member of the list is a com object (I think) and I'm converting them to integers (or to None if not numberic) but my method seems very silly. Is this the best way to go about it? It does exactly what it should, but it seems like a lot of extra BS to convert my object to a string to a float to a rounded integer! Don't laugh. I'm new at this! THE SCRIPT:-- import win32com.client xlApp = win32com.client.Dispatch("Excel.Application") f = r"C:\py\TrafficVolumes\xlTestDocs\3125113A.xls" xlApp.Visible = 0 xlApp.Workbooks.Open(f) list = xlApp.ActiveWorkbook.ActiveSheet.Range("Q13:Q36") print list print "\n" def comObjToInteger(myObj): try: s = str(myObj) fl = float(s) integer = int(round(fl)) return integer except: return None for i in list: print comObjToInteger(i) xlApp.ActiveWorkbook.Close(SaveChanges=0) xlApp.Quit() del xlApp #clean up -- THE RESULT: >>> the list: ((4.7998,), (u'*',), (2.0,), (1.6001,), (5.5996,), (19.399,), (25.0,), (38.797,), (32.797,), (21.0,), (24.0,), (17.399,), (22.801,), (22.601,), (33.797,), (35.399,), (29.199,), (35.399,), (32.203,), (26.0,), (24.399,), (22.801,), (14.0,), (11.6,)) my converted values: 5 None 2 2 6 19 25 39 33 21 24 17 23 23 34 35 29 35 32 26 24 23 14 12 -- -- http://mail.python.org/mailman/listinfo/python-list
RE: convert COM obj to integer
Well that looks quite nice, so I'll work that into my script. Thanks!!! That 1-tuple business was confusing me, and I was getting errors stating something about converting an object, so as you can see, I was grasping at straws. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steve M Sent: Wednesday, November 02, 2005 3:56 PM To: python-list@python.org Subject: Re: convert COM obj to integer I don't know exactly what a COM object is, but those aren't them. The win32com package takes care of converting everything to Python types. The excel call returns a tuple of tuples. That is, the outer tuple is the sequence of rows, and each such row is itself a tuple with one member per column requested. Since you only request one column, it is a one-item-long tuple, also called a 1-tuple. That is demonstrated by the result of print'ing the list. By the way, you shouldn't use 'list' as a name because it is also the name of a built-in function. And it isn't a list anyway, it's a tuple. Now, each number is in fact already a primitive Python object of type float. (The asterisk is a unicode string.) So you want to convert the floats into integers, and it looks like you want to round rather than truncate. table = xlApp.ActiveWorkbook.ActiveSheet.Range("Q13:Q36") converted_values = [] for row in table: value = row[0] #get the first (and only) item in the tuple try: value = round(value) except TypeError: #value is not a float value = None else: value = int(value) #turn the float into an int converted_values.append(value) print converted_values By the way, if you wonder how I knew to catch the TypeError, I just fired up the interactive Python interpreter, and typed this: round(u'*') -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
how to open a windows folder?
I'd love to be able to open up a windows folder, like c:\temp, so that it pops up visually. I know how to drill down into a directory, but I can't figure out how to open one up on screen. Would I have to make a call to windows explorer in a similar way that I hit Excel with: from win32com.client import Dispatch Excel = Dispatch("Excel.Application") Any clues? -- http://mail.python.org/mailman/listinfo/python-list
RE: how to open a windows folder? THANKS!
import os os.startfile ("c:/temp") That was painless and did the trick! Thanks Tim! -- http://mail.python.org/mailman/listinfo/python-list
pyKML: where to get it?
When trying to download pyKML at sourceForge, it says "No File Packages Defined" ;( Does anyone know where I can get pyKML? TIA Kev. -- http://mail.python.org/mailman/listinfo/python-list
Google Earth contact? (OT, sort of...)
Sorry if this is an off topic shot in the dark, but... Does anyone know a contact for anyone that works for Google Earth? I wanted to shoot 'em an email about a possible enhancement, but they're smart enough to not leave contact info ANYWHERE on their websites. -- http://mail.python.org/mailman/listinfo/python-list
seeking the "Hello World" of Packages
I'm trying to get an idea of how packages work and I've read about it in the Py Tutorial and Nutshell, but I'm still craving a concrete example that I can poke through. Does anyone have a really basic package that does very little that I could look at? What I've gathered thus far is that a package is simply a directory, say C:\MyPackage, that would contain __init__.py which tells Python to be aware of all the other modules in C:\MyPackage. Am I correct? C:\MyPackage\ \__init__.py \justPrintHelloWorld.py \multiply5By10.py Would I expect the following behavior?: >>>import MyPackage >>>MyPackage.justPrintHelloWorld "Hello World" >>>MyPackage.multiply5by10 50 -- http://mail.python.org/mailman/listinfo/python-list
RE: interactive programme (voice)
http://www.cs.unc.edu/~parente/tech/tr02.shtml loads of fun. -- http://mail.python.org/mailman/listinfo/python-list
RE: wxPython, dynamically modify window
I think that you'll just need to change the frame size property when you hit your checkbox... -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Grant Sent: Tuesday, December 12, 2006 12:02 AM To: python-list@python.org Subject: wxPython, dynamically modify window Hi, I am looking for a tip. I have a panel and a checkbox. When I check the checkbox, I would like to add buttons to the panel (dynamically). When the checkbox is unchecked, the buttons should not appear (be deleted)---all the while, the window should resize if necessary. If you have a simpler example, that is fine. I just need a hint as to how you dynamically change the widgets and their layouts. Looking at the wx demos, there is something close wx.lib.expando, but this is just modifying a particular widget. Thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
open a directory in widows
If I want "C:\temp" to pop open on screen, how do I do it? -- http://mail.python.org/mailman/listinfo/python-list
formatted string like---> u'720 S'
I'm building a dictionary from values a database and upon print the dictionary I see key value pairs like this: u'Briarcliff' : [u'2500 E'], u'Shumway' : [ u'2600 E'] do I need to slice off the "u", or anything? I know it has something to do with unicode but I don't know how to treat it. -- http://mail.python.org/mailman/listinfo/python-list
RE: newbie question: parsing street name from address
Look at the string.split() built-in, then you could use s.isalpha & s.isdigit to test each word... regular expressions would be the way to go, but that's a bit to chew on if you're getting started with string methods. You'll need to look at list indexing as well. Kev SLC DOT GIS -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of cjl Sent: Thursday, June 21, 2007 7:47 AM To: python-list@python.org Subject: newbie question: parsing street name from address P: I am working on a project that requires geocoding, and have written a very simple geocoder that uses the Google service. I would like to be able to extract the name of the street from the addresses in my data, however they vary significantly. Here a some examples: 25 Main St 2500 14th St 12 Bennet Pkwy Pearl St Bennet Rd and Main st 19th St As you can see, sometimes I have the house number, and sometimes I do not. Sometimes the street name is a number. Sometimes I simply have the names of intersecting streets. I would like to be able to parse the above into the following: Main St 14th St Bennet Pkwy Pearl St Bennet Rd Main St 19th St How might I approach this complex parsing problem? -CJL -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
google maps api for py?
I see that the weapon of choice for google maps is javascript... Is there anything for python? Kev -- http://mail.python.org/mailman/listinfo/python-list
Win XP "Sleep" mode: can Py wake up?
Does anyone have any experience having python deal with sleep mode? I'd love to run something that would hear a sleep event coming and pickle some data before sleep, then after coming out of sleep, unpickle... Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list
pyTTS broken : (
Importing pyTTS works, but then it bombs... any ideas? This worked without a hitch on my old computer! >>> import pyTTS >>> tts = pyTTS.Create() Traceback (most recent call last): File "C:\", line 1, in ? File "c:\Python24\Lib\site-packages\pyTTS\__init__.py", line 28, in Create raise ValueError('"%s" not supported' % api) ValueError: "SAPI" not supported -- http://mail.python.org/mailman/listinfo/python-list
RE: pyTTS broken SOLVED
I was using python 2.4.1 which was the problem. Upgrading to 2.4.4 fixed it... Thanks! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fredrik Lundh Sent: Friday, December 21, 2007 12:41 PM To: python-list@python.org Subject: Re: pyTTS broken : ( Bell, Kevin wrote: > Importing pyTTS works, but then it bombs... any ideas? This worked > without a hitch on my old computer! > >> >> import pyTTS > >> >> tts = pyTTS.Create() > > Traceback (most recent call last): > File "C:\", line 1, in ? > File "c:\Python24\Lib\site-packages\pyTTS\__init__.py", line 28, in Create > raise ValueError('"%s" not supported' % api) > > ValueError: "SAPI" not supported SAPI is Microsoft's Speech API. Have you installed the SAPI core libraries on your new computer? http://www.mindtrove.info/articles/pytts.html#prerequisites If you're planning to redistribute PyTTS applications, see: http://support.microsoft.com/kb/320207 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
send pdf or jpg to printer
Does anyone have any suggestions on printing pdf's? These pdf's don't change much, so if it be more straight forward to convert them to jpgs, or another format, then that'd be fine too. Thanks in advanced, Kevin -- http://mail.python.org/mailman/listinfo/python-list
search an entire website given the homepage URL
I know I can use urllib2 to get at a website given urllib2.urlopen(url) but I'm unsure how to then go through all pages that are linked to it, but still in the domain. If I want to search through the entire python website give the homepage, how would I go about it? I don't reinvent the wheel if someones already written a module for parsing out the links and drilling through them! TIA KEV -- http://mail.python.org/mailman/listinfo/python-list
Re: search an entire website given the homepage URL
>use a search engine (try the search box in the upper right corner). >using a spider to download the entire site just so you can "search through >it" is bloody impolite. Really? I'd argue that's impolite only if you're an impolite person with a rude agenda, which is not what I had in mind, but thanks for the ethics lecture as well as the pointer ; ) I assure you that I harbor no nefarious scheme. Isn't it common for folks to watch the stock market, or real estate listings, for example? I'll look into to tools you mentioned, and thanks again! -- http://mail.python.org/mailman/listinfo/python-list
Re: search an entire website given the homepage URL
Fredrik wrote: to grab entire sites ? try doing that on a commercial data provider's site, and chances are that you'll end up being banned (or sued) within hours ... - Me: Nope, I never said that to start with... Well I certainly am learning a lot. I never said I intended to download anyone's entire website, as was assumed, but it's been fun to see how folks feel about it anyway! I would like some feedback about my actual intention though, which is to scrape local newspaper websites for the names of people that I work with. Twice this month, colleagues have unknowingly been in the newspaper, and only became aware of it because someone stumbled across the line in the article. To write a script that would crawl around testing for my own name, or that of my colleagues, wouldn't seem uncouth to me, but I'm new at this stuff. It seems impolite for newspapers to use someone's name without informing them of it, for sure, but you can't count on journalists to call you up. Would this application of a spider be impolite? Bell, Kevin wrote: >>use a search engine (try the search box in the upper right corner). > > >>using a spider to download the entire site just so you can "search > > through >it" is bloody impolite. > > Really? I'd argue that's impolite only if you're an impolite person > with a rude agenda, which is not what I had in mind, but thanks for > the ethics lecture as well as the pointer ; ) I assure you that I > harbor no nefarious scheme. Isn't it common for folks to watch the > stock market, or real estate listings, for example? > > I'll look into to tools you mentioned, and thanks again! > > I think Fredrik's right: the intarweb is supposed to be distributed, not live on your desktop. Folk who watch the stock market don't download twenty years' worth of data in one afternoon, they generally subscribe to real-time feeds that are relatively low volume. regards Steve -- http://mail.python.org/mailman/listinfo/python-list
py on windows Mobile 5.0?
Does anyone know if/how to go about using python on a windows mobile 5.0 PDA? Kevin -- http://mail.python.org/mailman/listinfo/python-list
hide python window
When I run a script, how can I make it run in the background? I don't want to see the command window because it runs all day. I'm on windows... -- http://mail.python.org/mailman/listinfo/python-list
hide python window, con'td
Great! And now that it's hiding w/ .pyw, how would I kill it if I want? Just log off, or is there a better way? Kevin -- http://mail.python.org/mailman/listinfo/python-list
RE:RE: hide python window, cont'd
Bell, Kevin wrote: > Great! And now that it's hiding w/ .pyw, how would I kill it if I want? > Just log off, or is there a better way? > > Kevin > > >>JOE WROTE: >>Close it in the Task Manager? I don't see it in the task manager. -- http://mail.python.org/mailman/listinfo/python-list