<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Accessing variables from a file' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Accessing variables from a file' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 18:14:17 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 18:14:17 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Accessing variables from a file</title>
      <link>http://www.programmersheaven.com/mb/python/430530/430530/accessing-variables-from-a-file/</link>
      <description>Hi,&lt;br /&gt;
I have 2 files file1 &amp;amp; file2.&lt;br /&gt;
I am trying to open file1 and print str1 and n in file2.&lt;br /&gt;
Code:&lt;br /&gt;
&lt;br /&gt;
file1:&lt;br /&gt;
str1 = "192.168.10.1"&lt;br /&gt;
...&lt;br /&gt;
n =var.split('.')[3]&lt;br /&gt;
print n&lt;br /&gt;
&lt;br /&gt;
file2:&lt;br /&gt;
&lt;br /&gt;
with open(r"txt.py","r") as f:&lt;br /&gt;
            for line in f:&lt;br /&gt;
                if re.search("str1", line):&lt;br /&gt;
                    o1 = str1&lt;br /&gt;
                    print o1&lt;br /&gt;
               if re.search("n", line):&lt;br /&gt;
                    o2 = n&lt;br /&gt;
                    print o2&lt;br /&gt;
        f.close()&lt;br /&gt;
&lt;br /&gt;
This throws an error:&lt;br /&gt;
global name 'str1' is not defined&lt;br /&gt;
&lt;br /&gt;
Can someone please help me with this?&lt;br /&gt;
Thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/430530/430530/accessing-variables-from-a-file/</guid>
      <pubDate>Wed, 05 Dec 2012 01:56:43 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Accessing variables from a file</title>
      <link>http://www.programmersheaven.com/mb/python/430530/430532/re-accessing-variables-from-a-file/#430532</link>
      <description>Maybe this can help:&lt;br /&gt;
&lt;a href="http://rosettacode.org/wiki/File_IO#Python"&gt;http://rosettacode.org/wiki/File_IO#Python&lt;/a&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/430530/430532/re-accessing-variables-from-a-file/#430532</guid>
      <pubDate>Wed, 05 Dec 2012 02:42:24 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Accessing variables from a file</title>
      <link>http://www.programmersheaven.com/mb/python/430530/430533/re-accessing-variables-from-a-file/#430533</link>
      <description>Can someone please help?&lt;br /&gt;
Thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/430530/430533/re-accessing-variables-from-a-file/#430533</guid>
      <pubDate>Wed, 05 Dec 2012 02:42:41 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Accessing variables from a file</title>
      <link>http://www.programmersheaven.com/mb/python/430530/430548/re-accessing-variables-from-a-file/#430548</link>
      <description>Thanks for your reply. From file2 I would like to print str1 variable by opening file1 &amp;amp; closing it&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/430530/430548/re-accessing-variables-from-a-file/#430548</guid>
      <pubDate>Thu, 06 Dec 2012 04:55:04 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>