jlm699 320 Veteran Poster
print(command)
    cursor.execute(command)
    db.commit
    cursor.close()
    db.close()

Can you give us some example output from the print(command) trace code? It could be as simple as a missing quote or an improper tablename. Also, where is tablename even coming from? I don't see it in your code anywhere.

jlm699 320 Veteran Poster

I have tried both open(filename, 'r') and open(filename, 'rb')

I can get the file loaded into a string and then try
print binascii.crc32(file-in-string)

Still just gives me negative integers, what I want is the 8-char hexvalue.

Use 'rb', and RTFM

Use string formatting to print the hex value, just as the example in the docs shows you.

jlm699 320 Veteran Poster
AdressBook = ['Eve', 'Bob', 'Mike', 'Tom', 'Jane']

for x in AdressBook:
    print x, '\n'

f = open('C:\Documents and Settings\Henry\My Documents\Python_Stuff\Letter.txt', 'r+')

for a in AdressBook:
    x = AdressBook.index(0)
    for i in f:
        print i % (x)
    AdressBook.pop(0)

Confuzzled...

I'm confuzzled by your code. Do you know what list.index(x) does? It returns the index of item x in the list. If you were hoping to retrieve the first item of the AdressBook list (by the way you spelled Address wrong), you should be using slicing AdressBook[0] or even simply use pop, as that will return the value that gets removed.

So basically I'd change your final loop like so:

for a in AdressBook:
    x = AdressBook.pop(0)
    for i in f:
        print i % (x)

But this raises the question, why are you popping from the Address book? Why not just simply iterate over it and use those values? ie,

for addy in AddressBook:
    print i % addy

I fail to see the point of iterating over your file (which I presume contains a single line containing '%s'). What is it that you're trying to achieve?

jlm699 320 Veteran Poster

Don't convert the tuple to a string with str . Then you should be good to go.

The join method requires an iterable. Notice all the extra spaces in your output. This is because instead of joining each element of the tuple by spaces, you've made it join each letter in the string with spaces.

Look:

>>> t = ('Two', 'words')
>>> t
('Two', 'words')
>>> str(t)
"('Two', 'words')"
>>> ' '.join(str(t))
"( ' T w o ' ,   ' w o r d s ' )"
>>> ' '.join(t)
'Two words'
>>>

Get it?

jlm699 320 Veteran Poster

There's another post in this forum posted earlier today (or maybe late yesterday depending on your timezone).

It gives a working example of logging into a site. In his example he sends headers to spoof using a Mozilla web browser.

jlm699 320 Veteran Poster

The line is static, it's not dynamic!

What you can do is capture the resize event and simply adjust the width of the static line to the width of the window using something like getsize().

jlm699 320 Veteran Poster
for element in my_set:
    print ' '.join(element)

This hinges on each element being a tuple. IT will join each index of the element together with a space in between...

jlm699 320 Veteran Poster

but the list of tuples could be easily sorted.

Yeah, that link I provided actually demonstrates a sorting method as such: sorted(_, key=lambda x: -x[1]) EDIT: By the way, the '_' should be replaced by your variable name or the data itself if you were to implement this in a script. The usage of '_' is really only useful in the interpreter as a shortcut for the last return value.

jlm699 320 Veteran Poster

This isn't builtin, but my first hit on a google search for 'python list frequency' was this:

>>> alist = [ '1', '1', '2', '1', '3', '4', '1', '3']
>>> [(a, alist.count(a)) for a in set(alist)]
jlm699 320 Veteran Poster

Using your example string, we can separate at the whitespace using split(), and then locate the index of "welcome" using index(). Finally slicing the list by the result of index() + 1 will give us "to".

Here's some examples of using the above principals:

>>> example_msg = "Hello, welcome to DaniWeb"
>>> example_words = example_msg.split()
>>> index = example_words.index('welcome')
>>> example_words[index + 1]
'to'
>>>

Hope that's clear enough.

jlm699 320 Veteran Poster

There's no straight forward way to convert the strings 'True' and 'False' to boolean True or False, so you're best bet is probably:

if test.lower() == 'true':
    test = True
elif test.lower() == 'false':
    test = False

You could shorten those conditionals even further by only taking into account the first letter:

if test.lower()[0] == 't':
    test = True
elif test.lower()[0] == 'f':
    test = False

Considering you don't specifically need to validate the second case, you could simply use else: , and going even further you could simplify the assignment into a single line like so:

test = [False, True][test.lower()[0] == 't']
jlm699 320 Veteran Poster

Using your example string, we can separate at the whitespace using split(), and then locate the index of "welcome" using index(). Finally slicing the list by the result of index() + 1 will give us "to".

Using it for finding a row of text x lines further should be a relatively similar process as long as each line is in a list; however the major difference would be iterating over the lines, and then searching each line for the desired word, then using the index of that line plus x to find the desired line in the outermost loop.

jlm699 320 Veteran Poster

Firstly, you can use glob to get a list containing the name of each directory that starts with td like such: dirs = glob.glob(td.*) You can find the documentation about glob here.

Next, you'll want to iterate over the list that glob returns by doing something along the lines of for dir in dirs: .

Finally, to remove there exists a built-in os.rmdir(dir) which will remove the directory specified. Read up on the various operating system interfaces that the os module offers here.

jlm699 320 Veteran Poster

Refer to documentation here.

The first argument contains your arguments for the process itself so it needs to be a single element (list, tuple, etc). The remainder of parameters get passed to the Popen init function. Refer here to the remainder of items you can pass using **kwargs.

jlm699 320 Veteran Poster

sys.argv provides you the string representation of cmd line params. 'True' and 'False' are both strings, and if a string has any content in it at all, the boolean representation is True. You should simply change your condition to if test.lower() == 'true': HTH

jlm699 320 Veteran Poster

Can you define this method? I am not sure I understand what you mean.

Binary read is simply opening the file under the mode 'read' plus 'binary'. Read up on the built-in open method here, and the answer will reveal itself.

jlm699 320 Veteran Poster

i came up with this to print the field

list = [["-","-","-"],["-","-","-"],["-","-","-"]]
def printschema():
	for x in list:
		print x[0],x[1],x[2]
printschema()
o - -
- - x
- - -

lijst[1][1]="o"
printschema()
o - -
- o x
- - -

i put it into a list to be able to edit the content

That's good there. My only suggestion would be to not use the identifier 'list' as it's a built-in python type.

>>> my_tup = (1,2,3,4,5)
>>> list(my_tup)
[1, 2, 3, 4, 5]
>>> help(list)
Help on class list in module __builtin__:

class list(object)
 |  list() -> new list
 |  list(sequence) -> new list initialized from sequence's items
 |  
 |  Methods defined here:
#.... Snipped for brevity... you get the point
jlm699 320 Veteran Poster

The only code I have are exact examples from online, and none of them work so it would much quicker to get a working version from someone rather than take the code from a random website.

Here's a better approach: provide us the code that you tried on your system. Explain to us what "doesn't work" (ie, expected output vs. observed output). Then we can help to resolve your issues.

This site isn't about solving your homework. We only help those who show effort. It's in the announcements. Please read all the rules and announcements before posting to any forum. That's internet science.

jlm699 320 Veteran Poster

The important note about the above solution is that when calling SMTP() zachabesh initializes it to connect to gmail's smtp server ( smtplib.SMTP("smtp.gmail.com", 0) ).

Python's smtplib relies on you having access to an existing smtp server or else it cannot work. Alternately, you can initialize SMTP in the way that you did previously and then use the connect method to connect to the server. Refer here for more info on this library (particularly the SMTP objects section)

jlm699 320 Veteran Poster

purely out of curiosity, I tried this and I get the old error:

import package.subpackage1.baseclass

class ClassA(package.subpackage1.baseclass.BaseClass):
    pass

My only question to you is, why would you want to do it in that way? I think it's easier to understand the following when reading through a piece of code:

from package.subpackage1.baseclass import BaseClass
class ClassA(BaseClass):
    pass

That seems to be the most straight forward method to get BaseClass into your code and would be easiest for someone debugging to follow. A quick search for BaseClass would lead them to the import statement instead of staring at package.subpackage1.baseclass and thinking it was some type of sub-class method or sub-sub-class that was initialized somewhere.

I've always liked Guido's philosophy that says code is read much more than it is written, so you should aim for high readability and easy traceability in your code. Hiding imports away in packages and using overly-complicated import methods seems to be very unpythonic. At least in my opinion.

jlm699 320 Veteran Poster

As I interpret your package structure, your import should go something like this:

from package.subpackage1.baseclass import BaseClass

class ClassA(BaseClass):
    pass
jlm699 320 Veteran Poster

Thanks a lot Jim for your comments.

jim My expect string gets found, because of you see the i, its value is 1 which means expect string is able to found the .*password string..

problem starts when i send the password from the sendline..
after sendline its not sending any response.

I don;t know why it is happening because ideally it should return some thing.. :(

When you send your password do you hit 'Enter' ? Add \n after your password to see if that helps.

jlm699 320 Veteran Poster

The tut's on the internet are a little complex.

In that case threading is likely too complex for you. There's plenty of examples of threading on this site, if you'd take the time to search this particular forum.

Also "open up 2 urls" is rather vague. You want to download the source code? Parse the XML? Launch a browser and direct it to those urls? Connect to a database? If ask questions in a clear and concise manner you'll get better responses and more of them.

jlm699 320 Veteran Poster

All I can tell is that your expect strings never get found. So you would be better to figure out how to do this on the command line, and then replicate those actions using pexpect (since pexpect basically spoofs you performing the same commands (sendline) and waiting for certain responses (expect))

As you can see from the pexpect failure, the last 100 characters of output from your command were the following:

buffer (last 100 chars): Generic January 2005
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
hostname%
jlm699 320 Veteran Poster

I don't know if this module has been updated to support xlsx, but it provides a method to convert xls to xml: xlrd

jlm699 320 Veteran Poster

thank s for the code. I have tried this but i keep getting the following error

maxval=int(data[0])
ValueError: invalid literal for int() with base 10: '-0.0539723'

However when i use float() instead, it works. Do you understand this error.

'-0.0539723' is not a valid integer since it is not a whole number. It is a floating point number, which requires the float() conversion. int() only works on whole numbers.

jlm699 320 Veteran Poster

Maybe as a sanity check print out the contents of ffmpeg_line before calling the subprocess to make sure you've actually constructed the proper system call.

Also, the shared computer... is it a different platform? What is the purpose of that setup? I could imagine if you were running a script on a linux box with your version of PYthon that is installed on a Windows machine you'd run into many, many problems.

jlm699 320 Veteran Poster

This belongs in the Hardware/Software -> Networking forum... If you know how to use ssh to create tunnels go that route. If you don't know how to do that, search google for the numerous guides that exist.

jlm699 320 Veteran Poster

I am still rather new to the Linux OS and need some detailed advice on the installation of Python3.1 on my Ubuntu machine.

Python3.1 is not in the Ubuntu package repository yet.

If you perform an apt-cache search python | grep -E "31|3\.1" do you get any hits?

Alternately try an apt-cache search python3 . If nothing comes up for either query then you'll need to go the manual route.

jlm699 320 Veteran Poster

i use pywinauto, so will be like tat... ur answer din point to my question...

Your grammar is atrocious, therefore your question makes no sense. It is unlikely that anyone will be willing or able to answer it in its current form. I suggest revising your question and asking in a clear, concise manner using proper grammar and spelling.

jlm699 320 Veteran Poster

The file Otickers.txt is not in the working directory. Try printing the output of os.listdir('.') to see what actually is in the directory, along with os.getcwd() to see which directory you're actually working in.

also, a major flaw in your code is that any exception caught within your try block will give you the output that opening tfile failed. You should only except the relevant code, which would be the open call. So change your code to look like this:

import urllib, datetime, sys
from optparse import OptionParser

if __name__ == '__main__':
    
    parser = OptionParser()
    parser.add_option("-f", "--file", dest="tfile", action="store", default = "t.txt",
                      help="read list from file")     
    (options, args) = parser.parse_args()
    tfile = options.tfile
        
    try:
        file = open(tfile, 'r')
    except:        
        parser.error("t file %s not found" % (tfile,))
        raise SystemExit

    t = file.readlines()
    for i in range(len(t)):
        if t[i].rstrip('\n') == "TUE":
            f = "tues"
            d = "2"
            print "f:", f
                
        if t[i].rstrip('\n') == "MON":
            f = "mon,"
            d = "1"
            print "f:", f

        file.close()                

        data = urllib.urlopen(url)

        for l in data:
            if l.find(f) != -1:                    
                r = l.split(',')
                x = 2
                while x < 4:                        
                    <<do something>>
                    x = x + 1
                 print "**********************************************************************************************************************"

Also, pretty sure <<do something>> isn't valid syntax :P

Oh, and you should avoid using file as an object name since file is a reserved word in Python.

jlm699 320 Veteran Poster

by convention only class names start with a capital letter.

I'm pretty sure the OP couldn't care less about convention. His coding style is quite unique:

My coding style is on purpose. I put great emphasis on human readability, which comes out in many ways, including generous whitespace.

I guess part of that "human readability" becomes capitalizing every parameter name as well.

jlm699 320 Veteran Poster
class Validate_Numeric ( wx . PyValidator ):
	def __init__ ( Self ):
		wx . PyValidator . __init__ ( Self )
	def Clone ( Self ):
		return Validate_Numeric ()
	def On_Text_Change ( Self, Event ):
		TextCtrl = Self . GetWindow ()
		Text = TextCtrl . GetValue ()
		if Text . isdigit() or Text == "":
			TextCtrl . SetBackgroundColour ( "White" )
		else :
			TextCtrl . SetBackgroundColour ( "Pink" )
		Event . Skip ()

Questionable_TextCtrl = wx . TextCtrl ( Self, wx . ID_ANY, validator = Validate_Numeric () )

Try removing the Binding statement all together. You don't need to bind a validator to enable it. If you declare it under the validator paramater of TextCtrl it should work automagically; however you may need to change the name of your On_Text_Change method to Validate . I've been outta the wx game for a while but I believe that's required...

Here's a Validator I've used in the past to force the user to enter values into certain TextCtrls:

class TextValidator(wx.PyValidator):
    def __init__(self):
        wx.PyValidator.__init__(self)
    def Clone(self): # Required method for validator
        return TextValidator()
    def TransferToWindow(self):
        return True # Prevent wxDialog from complaining.
    def TransferFromWindow(self):
        return True # Prevent wxDialog from complaining.

    def Validate(self, win):
        textCtrl = self.GetWindow()
        text = textCtrl.GetValue()

        if len(text) == 0:
            wx.MessageBox("Text input is required", "Error")
            textCtrl.SetBackgroundColour("pink")
            textCtrl.SetFocus()
            textCtrl.Refresh()
            return False
        else:
            textCtrl.SetBackgroundColour(
                wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            textCtrl.Refresh()
            return True
jlm699 320 Veteran Poster

my problem is the content class because i can't pass self to this class imust pass parent but is not corret can somone help me

Please clarify your question. What's "not correct"

jlm699 320 Veteran Poster

That will work as well. But close file then reopen it with the create upon open or you will merely be overwriting the existing file and have debris from the previous file at the end!

What wildgoose is trying to say here is make sure you open your new file in 'write mode' instead of trying to write with your 'read mode' file handler or another 'append mode' handler.

See, when you open a file using f = open(my_file, 'w') it will either create a new file, or clear the contents of an existing file with the same name (as defined by my_file ).

jlm699 320 Veteran Poster
from __future__ import with_statement

with open ('C:\\Documents and Settings\\Desktop\\file2.txt') as fil:
    f = fil.readlines()
    for line in f:
        line = line.split()
        i = float(line[2])
        if i in range(90, 99.99):
            print line

It gave me an error message:
IndexError: list index out of range

please suggest on this....Thanks

Notice what happens in my interpreter when I use the range that you provided:

>>> range(90,99.99)
C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\py\PyCrust.py:1:
DeprecationWarning: integer argument expected, got float
  """PyCrust is a python shell and namespace browser application."""
[90, 91, 92, 93, 94, 95, 96, 97, 98]
>>>

range returns a list of integers, and is not the best solution for test the bounds of a floating point number.

You're best bet is probably to use the comparison statements. Luckily for you, Python provides an easy way to check if a value is within parameters.

Consider the following example:

>>> my_numbers = [1,5,15,6,21,10]
>>> for each_number in my_numbers:
...     if 1 <= each_number < 10:
...         print each_number, 'is in the range (1,10]'
...     
1 is in the range (1,10]
5 is in the range (1,10]
6 is in the range (1,10]
>>>

Note that 10 was not included in the output. I used the 'less than' ( < ) operator instead of the 'less than or equal to' ( <= ) operator.

jlm699 320 Veteran Poster
from __future__ import with_statement

with open ('C:\\Documents and Settings\\jguleria\\Desktop\\file2.txt') as fil:
    f = fil.readlines()
    for line in f:
        line = line.split()
        for line[2] in line:
            if i in range(90, 100):
                print line

I want to do something like above
but iam getting an error message i is not defined..!!

Please suggest...Thanks

You never defined i . I believe you meant for i to contain the value of line[2] ; however you'll want to convert it to a float() before assigning it to i .

Also, remove the for line[2] in line: as that doesn't make sense syntactically or logically

EDIT: Also keep in mind your endpoints of range. The result of a range(a, b) has the following range: [a, b) meaning you'll get values 90 - 99.

jlm699 320 Veteran Poster

Yes, this is the column i want to access for range between (90, 100)
and print the lines having these values.

So after this please suggest something

I want my outputfile to be like:


gnl|dbS|13484888 gi|62750812 95 20 .......
gnl|dbS|22484118 gi|62750812 92 20 .........
lines with column 3 values between 90 -100 ( clored red)

Alright, so in that case you'll need to remove the for loop that iterates over line[2] and instead compare float(line[2]) to the desired value.

I hope you notice that I'm intentionally not hand feeding you this code because challenging yourself to learn how to put it all together is a stepping stone to becoming a programmer. So please don't take offense, as I'm only trying to help you help yourself.

jlm699 320 Veteran Poster

In the future please use code tags when pasting code in this forum as it makes your code more readable and thus more people will be willing to read your post and answer your question. Here's how to use code tags:

[code=python] # Put your code inside here

[/code]

Now here's what your code would look like had you used code tags:

with open ('C:\\Documents and Settings\\Desktop\\file2.txt') as fil:
    f = fil.readlines
    for line in f:
        line.split()
        for text in line[2]:
            text = '90.00'
            if float(text) <100:
                result = line

Now with the indentation and syntax highlighting I can immediately see that you forgot to actually call readlines . So change the line f = fil.readlines so that it reads f = fil.readlines() .

Next, you forgot to assign the split line to a variable. You can assign it to itself so that your split line looks like this line = line.split() . So now line will contain the split list instead of the actual line.

The rest of your code is confusing to me... I suggest using print statements liberally to see what type of data you have and its contents at each point. That should help you figure out what's wrong with your last bit of code.

Run this to give you an example of what's going on (it's your code with the fixes I suggested above plus some debugging output):

with open ('C:\\Documents and Settings\\Desktop\\file2.txt') as fil:
    f = fil.readlines() …
jlm699 320 Veteran Poster

I am not able to do do it in this away

Why not? Show me the code you've created and describe the error that you get and I will gladly help you resolve it.

jlm699 320 Veteran Poster

Okay, somebody just posted this to the Google groups mailing list:

Hi.

When I go to http://wxpython.org/download.php , the page says "The links
below are for the binaries and source for wxPython *2.8.10.1"

*Good, I was trying to upgrade from 2.8.9.2

But when I scan through the page (as I did in April), for Microsoft
Windows, wxPython runtime, Python 2.6, win32-unicode, and click on that
link, I get to page:

http://sourceforge.net/projects/wxpython/files/

and that page lists only versions up to 2.7.1

If I instead right-click the link and "Copy URL" I get
http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2...
in the clipboard, and I can paste that into my address bar to download it.

So I've got 2.8.10.1 (sha1: 6602fb05272b7847576128313aacc447ffc107f6),
and am happy. But if there's something wrong with that page, I figured
somebody needed to know.

I'm using Firefox 3.0.11 on Windows XP Sp3.

DaveA

I tried it and was able to directly download the 2.8.10.1 installer by right clicking the link and "copy link location" then paste and open... So it would seem that the wxPython download page is doing some type of .php name resolution that is causing all this mess... Interesting!

Even more perplexing that searching on Sourceforge didn't show any current wxPython versions. So perhaps the problem is with Sourceforge after all. I don't know, I'm no doctor...

jlm699 320 Veteran Poster

As far as I understand, the Windows installer ulipad.3.9.exe sends along its own (subset) version of wxPython.

Right on, thanks for the suggestion.

The ulipad.3.9.exe windows installer automatically installed wx 2.8.7.1 (msw-unicode).

Acceptable solution for now, but I'd still like to update to the latest version of wx since Ulipad is still giving me issues. Although I'm 99.9% sure the issue is with Ulipad and not wx, I'd still like to try a sanity check.

jlm699 320 Veteran Poster

I'm sorry for that!
Here is a mirror I have tested and it works. Hope you will try it soon before all goes wrong

http://garr.dl.sourceforge.net/sourceforge/wxpython/wxPython2.8-win32-unicode-2.8.10.1-py25.exe

Nope, sorry same thing. You're saying that link allows you to download 2.8 and it works? Then maybe I AM crazy, because it still takes me to the "older versions" (2.7 and earlier) page.

There must be something wrong at sourceforge, right now every download request for wxpython2.8 flips into the wxPython2.7.1.2 page

Yes, this is exactly what I'm experiencing. So maybe I'm NOT crazy?!

jlm699 320 Veteran Poster

I feel like I'm losing my mind...

I uninstalled wxPython this morning and was going to reinstall with the latest version as I'm having peculiar problems with UliPad that I just downloaded yesterday.

Well after uninstalling the wx package and docs & demos I went to the wxPython page and followed the links to downloads -> Binaries. All of the links on that page take me to a source forge page that only lists installs of wxPython 2.7 and earlier... I tried searching for wxPython but could only find this "older versions" page.

Does anybody know where the latest binaries are hiding? Apparently all the links on the wxPython download page are broken... I know I could just get the latest SVN version and build it myself but this is nagging me.

Could somebody please try and take a look and tell me I'm not crazy... Or just as similarly tell me I AM crazy and give me the link to get my wxPython back up and running!

jlm699 320 Veteran Poster

>I won't allow myself to use that as it's just too foreign on a windows machine.
I don't agree.
Python guarantees that the '/' will be converted to whatever underlying platform is using. Hence it is *always* portable to use '/' instead of '\\'.
This guarantee is actually from the fact that C compiler itself use this convention.
So, use '/' and be portable.

Well that's good to know. I always used os.path.join for portability but if '/' is always converted then that's much simpler.

jlm699 320 Veteran Poster

Yes in Python the backslash is used to denote special characters:
\n is a newline character
\t is a tab
\\ is a backslash.

There's a number of ways to avoid that. One, use raw strings, which Python assumes has no special characters:

>>> print 'C:\foo\bar\lipsum\delorean'
C:ooar\lipsum\delorean
>>> print 'C:\\foo\\bar\\lipsum\\delorean'
C:\foo\bar\lipsum\delorean
>>> print r'C:\foo\bar\lipsum\delorean'
C:\foo\bar\lipsum\delorean
>>>

Alternately you could try the forward slash (which is a *nix path convention) like: 'C:/foo/bar/lipsum/delorean' I won't allow myself to use that as it's just too foreign on a windows machine. I prefer to use os.path.join, which oddly enough still requires the double slash on the drive letter, but aside from that no slashes required:

>>> import os
>>> os.path.join('C:\\', 'foo','bar','lipsum','delorean')
'C:\\foo\\bar\\lipsum\\delorean'
>>>
jlm699 320 Veteran Poster

Define "memory error". How about pasting your traceback.

jlm699 320 Veteran Poster

Here's how to open a file for reading and iterate over it:

f = open(my_file)
for line in file:
    # Do something to each line
f.close()

Here's how to split a string :

>>> my_text = "Here'ssomeTExt WithSomeMoreOver Here and then some more"
>>> my_text.split()
["Here'ssomeTExt", 'WithSomeMoreOver', 'Here', 'and', 'then', 'some', 'more']
>>>

As you can see, split returns a list so you can easily use slicing or indexing to access the third column (which would be index 2, btw)

Here's how to compare a string to a number by converting to float (you can also convert to int for integers, natch):

>>> my_number_text = '95.09'
>>> if float(my_number_text) < 100:
...     print 'That number was less than 100!'
...     
That number was less than 100!
>>>

And finally here's how you open a file for writing

f = open(my_file, 'w')
f.write('Some text here\n')
f.close()

There you go. Everything that you asked for. All in one place, now isn't that nice?

jlm699 320 Veteran Poster

You don't really need to be using regular expressions on something this simple though...

Yeah but it sounds like it's some type of built-in function to a larger utility that he used to run in perl. There's certainly better ways to build it, but he said it was URGENT so it must be life-or-death.

As they say, crises precipitate change....

jlm699 320 Veteran Poster

Let me get this straight... you want to replace your C: drive with a non-existant file called 'url' ?[/snark]

But seriously, the urlretrieve file needs to know what you want the save that url AS, not where you want to put it. If you don't supply the filename parameter it simply puts it in the current working directory, other wise it needs to know where you want it as well as what you want to call it.

import urllib
urllib.urlretrieve('url', 'c:\\url')