473,396 Members | 1,998 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.

"extern variable" in PYTHON:

I have a file fileA.py where my students input some data and fill in a certain portion of the code. There are a few functions they call from a module, fileB.py inside the file fileA.py. When they are calling functions, I do not want them to pass data as arguments , since that would confuse them a lot (they are 9th grade students). So, I want to make the data of fileA.py available to fileB.py. I cannot use

from __fileA__ import *

because, that will be a recursive call. I have already used it in fileA.py. So, I need a way out of this, where I can use variable defined in fileA.py to be used by fileB.py. I had an idea of creating a bypass.py such that

fileA calls functions from fileB.

Functions in fileB call functions from bypass.py

bypass.py accesses fileA.py and returns to fileB.py.

So, the recursion is kind of avoided.
Nov 3 '10 #1
2 7135
bvdet
2,851 Expert Mod 2GB
You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. # FileA.py
  2.  
  3. import FileB
  4.  
  5. a = 12
  6. b = 24
  7. c = 24
  8.  
  9. for attr in ('a', 'b', 'c'):
  10.     setattr(FileB, attr, eval(attr))
  11.  
  12. result = FileB.f()
Nov 3 '10 #2
dwblas
626 Expert 512MB
They should be able to understand writing the data to a file and closing the file. The function in fileB would open and read the file. Also, you can use a class attribute, but that is possibly beyond them as well.
Expand|Select|Wrap|Line Numbers
  1. ## file classC.py
  2. class Class_C:
  3.    test_string = "abc"
  4.    test_number = 1
  5.  
  6. ## fileA
  7. import classC
  8. import fileB
  9.  
  10. print classC.Class_C.test_string
  11. classC.Class_C.test_number = 2
  12. fileB.print_number()
  13.  
  14. ## fileB
  15. import classC
  16.  
  17. def print_number():
  18.     print "inside fileB", classC.Class_C.test_number 
Nov 3 '10 #3

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

Similar topics

7
by: Dominik Kaspar | last post by:
i'm used to java and its strict way of defining variables. so how is it possible to reach something like a class variable in python? with the following code i didn't have much succes... class...
7
by: Petr Prikryl | last post by:
Hi, Summary: In my opinion, the C-like prefix increment and decrement operators (++i and --i) should be marked as "syntax error". Current situation: try... (Python 2.4 (#60, ...)) >>> i =...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
2
by: K Williams | last post by:
I recently discovered that you can do the following: if currentdb.openrecordset ("select statement.....").eof = true then for cases when you just want to see if any records exist. This...
1
by: G Fernandes | last post by:
Hi, can someone tell me what the following words mean as per C/clc: 1) token 2) token sequence 3) scalar variable 4) vector
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
2
by: Gentian Hila | last post by:
Hi, I am a beginner with Visual C++ (I am using .NET 2002) MY problem is that sometimes the main dialog class dissapears from the class view ( so if my project is named Test, I cannot see CTestDlg...
1
by: bm | last post by:
I have few application variables storing shared important info in the IIS5 server. Now I want to cluster the web server so that users can still keeping using the service if one server down, and...
6
by: SuperFool | last post by:
This has got to be one of those questions only a serious newbie would come up with.... Basicly: I select all the city names in the table and turn them into a pull down menu (code below) print...
3
by: Yansky | last post by:
If I have the following code: var abc; if(!abc){ alert('test'); }
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.