Re: Basic file operation questions
In article <[EMAIL PROTECTED]>, Peter Nuttall wrote:
> On Wed, Feb 02, 2005 at 11:47:41PM -0500, Caleb Hattingh wrote:
>> Hi Alex
>>
>> Assuming you have a file called "data.txt":
>>
>> ***
>> f = open('data.txt','r')
>> lines = f.readlines()
>> f.close()
>> for line in lines:
>> print line
>> ***
>>
>
> Can you not write this:
>
> f=open("data.txt", "r")
> for line in f.readlines():
> #do stuff to line
> f.close()
sure you can
f = open("data.txt", "rb")
while [ 1 ]:
line = f.readlines()
if not line:break
line = somethingelse ...
f.close()
>
> Pete
--
http://mail.python.org/mailman/listinfo/python-list
Postgres COPY Command with python 2.3 pg
Hi to all,
can some one point me to the correct way, how to use PostgreSQLs "COPY" feature
from within python ?
What i want to do is:
connect
start transaction
drop current tablecontens
copy new content from STDIN # file need more privileged user rights
commit transaction
using psql it works fine, but i dont know how to get it working in python.
Ive already made the calls but the changes never apper, and no error.
my suggestion was, that "db.query("input|input|input") doesnt work as STDIN for
the Database, and i tryed db.putline() but no success.
Kind regards for any help
Michael Lang
--
http://mail.python.org/mailman/listinfo/python-list
Re: Postgres COPY Command with python 2.3 pg
On 2005-02-15, @(none) <""> wrote:
> Michael Lang wrote:
>> using psql it works fine, but i dont know how to get it working in python.
>> Ive already made the calls but the changes never apper, and no error.
>
> Which Postgres module are you using? I had the exct same problem when I
> first started using pyPgSQL, until I figured out that I needed to do:
>
> db = PgSQL.connect(DSN)
> db.autocommit = 1
> con = db.cursor()
Hi,
im using PostgreSQL RPM from Fedora Core3
$ rpm -q postgresql-python
postgresql-python-7.4.6-1.FC3.2
code looks like
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pg
>>> db = pg.DB('bind9', '192.168.192.2', 5432, None, None, 'named', None)
>>> dir(db)
['_DB__args', '_DB__attnames', '_DB__pkeys', '__doc__', '__init__',
'__module__', '_do_debug', 'clear', 'close', 'db', 'debug', 'delete',
'endcopy', 'fileno', 'get', 'get_attnames', 'get_databases', 'get_tables',
'getline', 'getlo', 'getnotify', 'insert', 'inserttable', 'locreate',
'loimport', 'pkey', 'putline', 'query', 'reopen', 'reset', 'source',
'transaction', 'update']
so theres no cursor i could try like your code does ...
thanks for your response ...
>
> In my code.
--
http://mail.python.org/mailman/listinfo/python-list
