Regular expression worries

2006-10-11 Thread CSUIDL PROGRAMMEr
folks
I am new to python, so excuse me if i am asking stupid questions.

I have a txt file  and here are some lines of it

Document Keyword
Keyword Keyword
Keyword Keyword Keyword Keyword
Keyword Keyword Keywordhttp://mail.python.org/mailman/listinfo/python-list


stripping parts of elements in a list

2006-10-28 Thread CSUIDL PROGRAMMEr
folks,
I am  new to python.

I have a list made of elements

['amjad\n', 'kiki\n', 'jijiji\n']
I am trying to  get rid of '\n' after each name.
 to get list as
['amjad','kiki','jijiji']

But list does not have a strip function as string does have.

is there any solutions

Is there a way this can be done??

-- 
http://mail.python.org/mailman/listinfo/python-list


looping through two list simultenously

2006-10-29 Thread CSUIDL PROGRAMMEr
folks
I have two lists

 i am trying to loop thorough them simultenously.

Here is the code i am using

f1 = os.popen('ls  chatlog*.out')
data1=f1.readlines()
f1.close()

data1=[x.strip() for x in data1]
f1 = os.popen('ls  chatlog*.txt')
data=f1.readlines()
f1.close()
for eachline in data1 and line in data:

filename='/root/Desktop/project/'+ eachline
print filename
outfile=open(filename,'r')
filename1='/root/Desktop/project/' + line
print filename1

I get the error that line is not defined.
Traceback (most recent call last):
  File "list.py", line 16, in ?
for eachline in data1 and line in data:
NameError: name 'line' is not defined

Is there any efficient doing this

-- 
http://mail.python.org/mailman/listinfo/python-list


Replacing line in a text file

2006-09-22 Thread CSUIDL PROGRAMMEr
Folks
I am trying to read a file
This file has a line containing string  'disable = yes'

I want to change this line to 'disable = no'

The concern here is that , i plan to take into account the white spaces
also.

I tried copying all file int list and then tried to manipulate that
list

But the search is not working

Any answer

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting from command line options to file

2007-04-20 Thread CSUIDL PROGRAMMEr
On Apr 16, 1:08 pm, Michael Hoffman <[EMAIL PROTECTED]> wrote:
> CSUIDL PROGRAMMEr wrote:
> > hi folks
> > I am new to python. I have a module does call a os.command(cmd) where
> > cmd is a rpm command.
> > Instead of using os.command and getting the results on command line ,
> > i would like to dump the output in a file. Is os.command(cmd >
> > filename)  the most efficient command??
>
> I think the best thing to do would be something like this (Python 2.5):
>
> from __future__ import with_statement
> import subprocess
>
> with file("test.out", "w") as outfile:
>  subprocess.check_call(["ls", "/etc"], stdout=outfile)
> --
> Michael Hoffman


but what if i have python which  is 2.4??


-- 
http://mail.python.org/mailman/listinfo/python-list


Redirection problem

2007-04-23 Thread CSUIDL PROGRAMMEr
I am new to python. so be patient with me

I am trying to redirect the output of os.popen command to a file. I
want to append to that file. but instead of appending. The file only
shows last command that was writtenn to  it.



 filehandle= open("/root/yhpc-2.0/installer/yhpc-log" ,"a+");
filehandle.write(" Command executed is " + cmd);
try:
  pipe= os.popen('%s > /root/yhpc-2.0/installer/yhpc-log' %cmd );
except : IOError;
  filehandle.close();


Any  suggestion would help.



filehandle.close();

-- 
http://mail.python.org/mailman/listinfo/python-list


defining user exceptions

2007-04-24 Thread CSUIDL PROGRAMMEr
I am trying to write  a user defined exception that will catch for
failed dependencies when a rpm is installed

try:
 rpm -ivh  xxx.rpm --force;
except  RPMError:
   print  RPM failed dependency


Can some one tell me how to define this RPMError. I looked at python
docs but they were not useful.

-- 
http://mail.python.org/mailman/listinfo/python-list


RPM error

2007-04-24 Thread CSUIDL PROGRAMMEr
Hi folks

 I am trying to write a program that will install RPM.
IS there any built in Exception in python that will catch the faied
dependencies in python.

Also if not how can i write one ??


thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


RPM error

2007-04-24 Thread CSUIDL PROGRAMMEr
Hi folks
I am new to python
I am trying to write a program that will install rpm
using rpm -ivh xxx.rpm

I want to know if python has in-built exceptions  to catch no-
dependencies error.

If not how can i build them

thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


getting from command line options to file

2007-04-16 Thread CSUIDL PROGRAMMEr
hi folks
I am new to python. I have a module does call a os.command(cmd) where
cmd is a rpm command.
Instead of using os.command and getting the results on command line ,
i would like to dump the output in a file. Is os.command(cmd >
filename)  the most efficient command??


thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


getting the name of hyperlinks in a file

2007-01-12 Thread CSUIDL PROGRAMMEr
folks,
I am trying to write a script that would open a download server and
download all the files  and store them in a list

for example Download server is
http://download.fedora.redhat.com/pub/fedora/linux/core/updates/5/SRPMS/


is there any way this can be done in python??

-- 
http://mail.python.org/mailman/listinfo/python-list


parsing a file name

2007-01-12 Thread CSUIDL PROGRAMMEr
I have a filename
cairo-2.3.4.src.rpm
Is there any way i can only get 2.3.4 from this file name
thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


url lib

2009-03-20 Thread CSUIDL PROGRAMMEr
Hello
I am a novice python progammer

I am just writing a script that will automatically write my /etc/
yum.repos.d/* files in linux.

the problem is i am trying to connect to a secure repo and pass
username and password to the baseurl .

here is the baseurl
baseurl=http://USERNAME:passw...@ydl.net/yum/6.1/../../../.

I have tried using the urllib2 in python

the code i tried was
req=urllib2.Request("http://USERNAME:passw...@ydl.net/cell/yum/6.1/
base)
try: urllib2.urlopen(req)
except urllib2.URLError,e:

Where Username:PASSWORD are speciefied by user

The Error i got was
File "/usr/lib/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
  File "/usr/lib/python2.4/urllib2.py", line 358, in open
response = self._open(req, data)
  File "/usr/lib/python2.4/urllib2.py", line 376, in _open
'_open', req)
  File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
result = func(*args)
  File "/usr/lib/python2.4/urllib2.py", line 1021, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.4/urllib2.py", line 980, in do_open
h = http_class(host) # will parse host:port
  File "/usr/lib/python2.4/httplib.py", line 592, in __init__
self._set_hostport(host, port)
  File "/usr/lib/python2.4/httplib.py", line 604, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: 'passw...@ydl.net'

How can i connect to the site with password?? Do i have to implement
the ssl certification??
--
http://mail.python.org/mailman/listinfo/python-list