全局变量错误

时间:2016-11-24 18:34:37

标签: python

   stack = ['','','','','','']
   global first
   global last
   first = 0
   last = 0
   print(stack)
   while True:
       def push():
           if 0 <= last:
               stack[last] = 'D'
               last = last + 1
               if last == 6:
               last = -1
           else:
               print("The stack is full.")
               print(stack)
        def pop():
           stack[last] = ''
           last == stack[last-1]
           print(stack)
           if first == last:
               print("The queue is empty")
       a = input("Push or pop. ")
       if a == 'push':
           push()
       elif a == 'pop':
           pop()

我已将last指定为全局变量但我收到此错误UnboundLocalError:在赋值之前引用的局部变量'last'。考虑到我最后一个全局变量,我不明白为什么错误建议不然,任何解决方案?

1 个答案:

答案 0 :(得分:-1)

main-exec必须位于<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-libraries</id> <phase>generate-resources</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <!-- win32 --> <artifactItem> <groupId>com.resources-win</groupId> <artifactId>ressources-win</artifactId> <version>1.0.0-SNAPSHOT</version> <type>pom</type> <destFileName>xdol.dll</destFileName> <outputDirectory>${project.build.directory}/temp/schemas</outputDirectory> </artifactItem> </artifactItems> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> </configuration> </execution> </executions> </plugin> 内。 Using global variables in a function other than the one that created them