Is there any better way to approach this problem?

H

Hitesh Joshi

Hi,

I am newbie python dude. I need few hints.

I created a DB table with following fields
UserID(PK), TimeStamp, Version, IP, Port

I need to insert these info from this .log file and the log file has
lines like following with some junk garbase like "attempt using client
software " I need to get rid of that.

10:03:54.527 (01) - User (xxx123) login attempt using client software
version (1.0.1.1) from IP (xxx.xxx.xxx.xxx) port (xxxx)

Create a while 1 loop, read line from file.. disect line and insert
'stuff' into those variables and then run a query from inside the
python to insert data... and do this untill EOF...
Is there any better way to approach this problem?

so if I have variable , let's say, TimeStamp, UserID, Version,
IPAddress and PortNum.. how can I disect this line and insert into
this variable?

Thank you,
hj
 
S

Sybren Stuvel

Hitesh Joshi enlightened us with:
Create a while 1 loop, read line from file [...] and do this untill
EOF...


Ehm... why not

for line in fileobj:
...
so if I have variable , let's say, TimeStamp, UserID, Version,
IPAddress and PortNum.. how can I disect this line and insert into
this variable?

Use a regular expression with groups.

Sybren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top