List Info

Thread: file open error




file open error
user name
2007-02-08 17:16:27
Hey guys,

I have this simple code and i cant seem to get it to run.
here is the code.


from os import *
import re

hostname =raw_input("Host name : ") or '<unknown>&#39;
mac_addr =input(&quot;Mac address : ")

filename=9;/etc/dhcpd.conf'
fh=open(filename)

m = re.match(hostname,fh.readlines())
if m!=None:
&nbsp;   m.group()


Here is the error I get when i try to run the code


monkeysee% python sys_wireless.py
Host name :
Mac address : 1234567
Traceback (most recent call last):
  File "sys_wireless.py", line 8, in ?
 &nbsp;  fh=open(&quot;/etc/dhcpd.conf&quot;,"r")
TypeError: an integer is required



I dont know what the issue is?

any hints ?



Re: file open error
user name
2007-02-08 17:33:14
On 09/02/07, Jalil <jalilsangmail.com> wrote:

Hi Jalil,

Because you're doing this:

> from os import *

It means that when you get to this line:

> fh=open(filename)

You're actually calling os.open, which is lower-level than
the
standard open() and expects different arguments.

Many people recommend not doing "from .. import *"
if you can possibly
avoid it because of this precise problem!

-- 
John.
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

Re: file open error
user name
2007-02-08 17:34:51
On Thu, Feb 08, 2007, Jalil wrote:
>
>   Hey guys,
>   I have this simple code and i cant seem to get it to
run.
>   here is the code.
>   from os import *
>   import re
>   hostname =raw_input("Host name : ") or
'<unknown>'
>   mac_addr =input("Mac address : ")
>   filename='/etc/dhcpd.conf'
>   fh=open(filename)
>   m = re.match(hostname,fh.readlines())
>   if m!=None:
>       m.group()
>   Here is the error I get when i try to run the code
>   monkeysee% python sys_wireless.py
>   Host name :
>   Mac address : 1234567
>   Traceback (most recent call last):
>     File "sys_wireless.py", line 8, in ?
>      
fh=open("/etc/dhcpd.conf","r")
>   TypeError: an integer is required
>   I dont know what the issue is?
>   any hints ?

It appears to me that your ``from os import *'' is biting
you in
the butt as the os.open command is being executed instead of
the
normal open.

Bill
--
INTERNET:   billCelestial.COM  Bill Campbell; Celestial
Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA
98040-0820; (206) 236-1676

``Liberty don't work as good in practice as it does in
speeches.''
    Will Rogers
_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )