<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'I seem to be missing a crucial piece here.' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'I seem to be missing a crucial piece here.' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Thu, 24 May 2012 00:01:07 -0700</pubDate>
    <lastBuildDate>Thu, 24 May 2012 00:01:07 -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>I seem to be missing a crucial piece here.</title>
      <link>http://www.programmersheaven.com/mb/python/416801/416801/i-seem-to-be-missing-a-crucial-piece-here/</link>
      <description>Hi everyone, this is my first post here. I've started python a few days ago and having programmed in VB for a couple years I'm fooled by this new language. There are a couple of concepts that I may be missing. I'm reading "A Byte of Python" which is a very good book, but I don't know why the author did not answer those questions in his book. &lt;br /&gt;
&lt;br /&gt;
1) When I declare a variable in the global field (which I apparently HAVE to give it a value, even if I am only going to decide what value to assign later in the program) and when I modify it from a function it stays the same. Here is an example:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
name = ""  #The variable that I want to use later

def getUsrName():

    name = raw_input("Please enter your name.\nChoice: ") #This is where I assign it a value, but it doesn't modify the global one. Instead working on its own copy.
    
    greetUsr(name) #The workaround I found is to link functions with functions, instead of going through each one in the global field.
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Also, is it possible to declare a variable but not give it a value ? Because if the user chooses the value of the variable I have to do Value = raw_input("Choose a value") at the declaration time, which is inconvenient. &lt;br /&gt;
&lt;br /&gt;
Any way around those problems?&lt;br /&gt;
&lt;br /&gt;
* I call "Global Field" the place that the code is resting outside every function. I don't know the proper name for this yet :(&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416801/416801/i-seem-to-be-missing-a-crucial-piece-here/</guid>
      <pubDate>Fri, 28 May 2010 21:17:03 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: I seem to be missing a crucial piece here.</title>
      <link>http://www.programmersheaven.com/mb/python/416801/416823/re-i-seem-to-be-missing-a-crucial-piece-here/#416823</link>
      <description>You can declare a variable with None value (It's the same as NULL in c), it means 'Nothing':&lt;br /&gt;
name = None&lt;br /&gt;
for tuples, dirs, arrays you can do this:&lt;br /&gt;
t = ()&lt;br /&gt;
d = {}&lt;br /&gt;
a = []&lt;br /&gt;
&lt;br /&gt;
If you want to change a global var from function, use global:&lt;br /&gt;
&lt;br /&gt;
name = None # it's empty, but declared&lt;br /&gt;
def getUsrName():&lt;br /&gt;
  global name&lt;br /&gt;
  name = 'someone'&lt;br /&gt;
&lt;br /&gt;
This changes the global name to 'someone'&lt;br /&gt;
&lt;br /&gt;
Hope this helps:&lt;br /&gt;
Imre Horvath&lt;br /&gt;
Regards: -blemidon-</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416801/416823/re-i-seem-to-be-missing-a-crucial-piece-here/#416823</guid>
      <pubDate>Sat, 29 May 2010 11:51:09 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: I seem to be missing a crucial piece here.</title>
      <link>http://www.programmersheaven.com/mb/python/416801/416828/re-i-seem-to-be-missing-a-crucial-piece-here/#416828</link>
      <description>Nice, it worked perfectly ! I wonder why no one bother to explain this stuff in every beginner's book I read &amp;gt;.^  Ah well.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416801/416828/re-i-seem-to-be-missing-a-crucial-piece-here/#416828</guid>
      <pubDate>Sat, 29 May 2010 16:40:50 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: I seem to be missing a crucial piece here.</title>
      <link>http://www.programmersheaven.com/mb/python/416801/416845/re-i-seem-to-be-missing-a-crucial-piece-here/#416845</link>
      <description>Using global vars for getting data from a function is not the preferred way.&lt;br /&gt;
&lt;br /&gt;
You can try:&lt;br /&gt;
&lt;br /&gt;
name = None&lt;br /&gt;
&lt;br /&gt;
def getUsrName():&lt;br /&gt;
  name = 'someone'&lt;br /&gt;
  return name&lt;br /&gt;
&lt;br /&gt;
name = getUsrName()&lt;br /&gt;
&lt;br /&gt;
It's nicer.&lt;br /&gt;
&lt;br /&gt;
Regards:&lt;br /&gt;
Imre Horvath</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416801/416845/re-i-seem-to-be-missing-a-crucial-piece-here/#416845</guid>
      <pubDate>Sun, 30 May 2010 02:21:58 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>This post has been deleted.</title>
      <link>http://www.programmersheaven.com/mb/python/416801/416846/this-post-has-been-deleted/#416846</link>
      <description>This post has been deleted.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416801/416846/this-post-has-been-deleted/#416846</guid>
      <pubDate>Sun, 30 May 2010 02:23:48 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>This post has been deleted.</title>
      <link>http://www.programmersheaven.com/mb/python/416801/416910/this-post-has-been-deleted/#416910</link>
      <description>This post has been deleted.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416801/416910/this-post-has-been-deleted/#416910</guid>
      <pubDate>Mon, 31 May 2010 23:52:46 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>
