473,795 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access to variable from external imported module

How to access to a variable (that value is not returned) from a module
imported?
And the variable is set at the module-level.

That module is external to my program, it's from another project so I
wann't modifying it.

Nov 23 '06 #1
17 1688
GinTon wrote:
How to access to a variable (that value is not returned) from a module
imported?
And the variable is set at the module-level.
import module
print module.variable

(have you read the Python tutorial?)

</F>

Nov 23 '06 #2
Sorry, I mean access to local variable from a method

import module
method(value)

I would to access to values that are created locally in that method

Fredrik Lundh ha escrito:
GinTon wrote:
How to access to a variable (that value is not returned) from a module
imported?
And the variable is set at the module-level.

import module
print module.variable

(have you read the Python tutorial?)

</F>
Nov 23 '06 #3
GinTon wrote:
Sorry, I mean access to local variable from a method

import module
method(value)

I would to access to values that are created locally in that method
after the method has executed? usually the return value?
or you want to get all local variables, then make a func/method

def f(a=1):
b=2
c=3
return locals() #X/Object(locals() )
--------
d=module.f()
print d['c'] # d.c

Robert
Nov 23 '06 #4
GinTon wrote:
Sorry, I mean access to local variable from a method

import module
method(value)
That's no access to a local variable of a method. It's a simple
function call.
I would to access to values that are created locally in that
method
Something with your interface seems horribly wrong.

Regards,
Björn

--
BOFH excuse #316:

Elves on strike. (Why do they call EMAG Elf Magic)

Nov 23 '06 #5
GinTon a écrit :
Sorry, I mean access to local variable from a method
One of the most surprising properties of local variables is that they
are, well... local.

Nov 23 '06 #6


GinTon,

I think this is what you want.
class Kdoi:
* *def __init__(self) : * *
* * * *self.Fdo()

* *def Fdo(self):

searchterm = 'help'
print searchterm #local

* * *self.searchter m = searchterm
* * *print self.searchterm #used inside the class

* * *Kdo.searchterm = searchterm #<<<<
* * *print Kdo.searchterm #used outside the class
Kdomore()
* *
class Kdomore(Kdo):
def __init__(self) :
self.Fdomore()

def Fdomore(self):
searchterm = Kdo.searchterm # <<<<
print searchterm

jim-on-linux
http://www.inqvista.com


On Thursday 23 November 2006 17:09, GinTon wrote:
Sorry, I mean access to local variable from a
method

import module
method(value)

I would to access to values that are created
locally in that method

Fredrik Lundh ha escrito:
GinTon wrote:
How to access to a variable (that value is
not returned) from a module imported?
And the variable is set at the
module-level.
import module
print module.variable

(have you read the Python tutorial?)

</F>
Nov 23 '06 #7
Thanks Robert, the best solution is get all local variables, else is
impossible access to them.

robert ha escrito:
GinTon wrote:
I would to access to values that are created locally in that method

after the method has executed? usually the return value?
or you want to get all local variables, then make a func/method

def f(a=1):
b=2
c=3
return locals() #X/Object(locals() )

--------

d=module.f()
print d['c'] # d.c
Nov 23 '06 #8
GinTon wrote:
Thanks Robert, the best solution is get all local variables, else is
impossible access to them.
if you don't want them to be local, why are you using local variables?

(have you read the Python tutorial?)

</F>

Nov 24 '06 #9

jim-on-linux wrote:
GinTon,

I think this is what you want.
class Kdoi:
Is that a typo?
def __init__(self) :
self.Fdo()
What is all this K and F stuff?
def Fdo(self):

searchterm = 'help'
print searchterm #local

self.searchterm = searchterm
print self.searchterm #used inside the class

Kdo.searchterm = searchterm #<<<<
print Kdo.searchterm #used outside the class
Kdomore()

class Kdomore(Kdo):
def __init__(self) :
self.Fdomore()

def Fdomore(self):
searchterm = Kdo.searchterm # <<<<
print searchterm
It's not apparent what the print statements are for -- are they part of
an attempt to debug your code?

What gives you the idea that this is what the OP wants or needs?

Nov 24 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4756
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
7
3066
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the correct cells within that worksheet. The Excel Book is made up of 12 worksheets named Jan-Dec. Each worksheet has columns labeled as each day of that month. Column 'A' is reserved for 19 rows named "room1 - room19". The data I am importing from the...
3
5337
by: ghadley_00 | last post by:
Hi, Does anyone know of a way I can write a script that imports a table from a particular .mde file? I don't seen any obvious way to do it as a macro. Any suggestions if it can be done as a macro or as a written module? My ultimate goal is to have script that clears info out of 1 table in an .mdb file, imports an identically structured table from a .mde file, runs an append query I have in place to copy the data from the imported
3
1550
by: Marco Aschwanden | last post by:
Hi I have a script that looks for modules and tries to load them. After loading I attach the "server"-API function to it. module = __import__(module_name, globals(), locals(), ) module.server = server.server_api Now, some modules need the "server" functionality on load/init. I tried to modify the globals():
1
3113
by: puremetal33 | last post by:
I have worked very little with Access and have hit a snag. My task right now is to import the data from a spreadsheet into an existing table in an Access database. I edited the .xls file so that fields are laid out the same L-R and made certain that the data is the same in both the .xls file and the table it is to be imported to have the same data type in each field. I follow the File>Get External Data>Import path and choose the .xls...
4
2102
by: noagbodjivictor | last post by:
I have a variable names actions in a module named qt_actions.py Well this is what I get: Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'actions'
1
1200
by: hjeff71 | last post by:
Ok, we've got this complicated form with 10000s of lines of vba code, doing all sorts of calculation, The forms are on several pcs, and the tables are on the server, (using the external link) Now we need to install those forms on many other pcs and are looking into buying liscencing, Along the road, someone suggested to have the forms in Outlook instead of Access, (Since every one has Outlook) My question is: Can a Form be imported...
4
6002
by: RgeeK | last post by:
I have a main module doStuff.py and another module utility.py. At the start of doStuff.py I call import utility.py Then I also proceed to initiallize some global variables sName = "" Then I create a class, some methods etc. In one of the methods I assign
6
26333
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this one table. My problem is I have two buttons I want to use this code for for the two buttons would put the data in different tables. I have tried copying and changing a few things and nothing will work for me. The code is set up in a module and then I...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.