473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to declare a LIST as GLOBAL in python

Can we declare using th keyword "global" in declaring a global array?

ie like global arr = []

This throws an error saying invalid syntax.
May 20 '10 #1
5 35758
dwblas
626 Expert 512MB
Not enough info. What is the code and what is the error message. Finally, you should not be using globals. Pass the list (not array) to the function and return it, or better still, use a class. A link to a book describing function args in case you don't know http://www.greenteapress.com/thinkpy...l/book007.html
May 20 '10 #2
I declared a list as I had to append some threads into it.
Expand|Select|Wrap|Line Numbers
  1. global th = []
  2. th.append(thread)
These 2 lines of code were written in one function. In another function I want to join them like:
Expand|Select|Wrap|Line Numbers
  1. for t in th
  2.      t.join()
  3.  
But this code throws an error telling that global th= [] is invalid syntax.
May 21 '10 #3
Glenton
391 Expert 256MB
@getmanup
When you say threads do you mean this kind of thread? I'm pretty sure that joining them is not valid. So what @dwblas was saying was that you should rather pass your "th" variable across explicitly.

Expand|Select|Wrap|Line Numbers
  1. def firstcode():
  2.      ...
  3.     th=[]
  4.     th.append(thread)
  5.     ...
  6.     return th
  7.  
  8. def nextmethod(th):
  9.     for t in th:
  10.         t.join()
But if you really want to make th global, just add
Expand|Select|Wrap|Line Numbers
  1. global th
  2. th=[]
to your code.
May 21 '10 #4
@Glenton
thank you so much... it worked

but u did say that joining threads like that is not a good idea...I am really in the beginner level...so could you explain why you said so..if its ok for u ...
May 21 '10 #5
Glenton
391 Expert 256MB
Um...I don't think you're using threads in the coding sense. Probably it's just a string, so don't worry about it. If you're not sure, then you're definitely not using them!
May 21 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sriram Chadalavada | last post by:
Hello everyone, I am a newbie to Python with experience in C programming. For my project, I am re-writing C routines as Python functions. I am currently using raw numerical values and was...
11
by: Laszlo Zsolt Nagy | last post by:
Hello, Do you know how to implement a really efficient self reordering list in Python? (List with a maximum length. When an item is processed, it becomes the first element in the list.) I would...
8
by: jerry.levan | last post by:
Hi, I have a file that contains a "tcl" list stored as a string. The list members are sql commands ex: { begin { select * from foo where baz='whatever'} {select * from gooble } end { insert...
19
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
2
by: TARUN | last post by:
I have a question about declaring the Global.ascx: In VS.NET I create a Solution, and there are 4 projects under it. They are put under 4 folders, but web pages would be called across the 4...
2
by: omprasad | last post by:
how to implemet the linked list in python programs
14
by: umesh chary | last post by:
how do i develop a algorithm for linked lists in python i want immediate answers
0
by: Trent Nelson | last post by:
Following on from the success of previous sprint/bugfix weekends and sprinting efforts at PyCon 2008, I'd like to propose the next two Global Python Sprint Weekends take place on the following...
0
by: Thomas Lee | last post by:
Anyone in Melbourne, Australia keen for the first sprint? I'm not sure if I'll be available, but if I can it'd be great to work with some others. Failing that, it's red bull and pizza in my lounge...
0
by: =?ISO-8859-1?Q?Tarek_Ziad=E9?= | last post by:
On Wed, Apr 16, 2008 at 8:40 PM, Michael Foord <fuzzyman@voidspace.org.ukwrote: We are trying to set up a team here in Paris, Personnally I would like to continue the work started in distutils...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.