Python

Moderators: None (Apply to moderate this forum)
Number of threads: 473
Number of posts: 1172

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Accessing variables from a file Posted by pplshlp on 5 Dec 2012 at 1:56 AM
Hi,
I have 2 files file1 & file2.
I am trying to open file1 and print str1 and n in file2.
Code:

file1:
str1 = "192.168.10.1"
...
n =var.split('.')[3]
print n

file2:

with open(r"txt.py","r") as f:
for line in f:
if re.search("str1", line):
o1 = str1
print o1
if re.search("n", line):
o2 = n
print o2
f.close()

This throws an error:
global name 'str1' is not defined

Can someone please help me with this?
Thanks
Report
Re: Accessing variables from a file Posted by Pelle-48 on 5 Dec 2012 at 2:42 AM
Report
Re: Accessing variables from a file Posted by pplshlp on 6 Dec 2012 at 4:55 AM
Thanks for your reply. From file2 I would like to print str1 variable by opening file1 & closing it
Report
Re: Accessing variables from a file Posted by pplshlp on 5 Dec 2012 at 2:42 AM
Can someone please help?
Thanks



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.