473,473 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

user variables

Sorry this must be really trivial, but I am new to Python...
suppose I defined
a=5
b=7
c=9

is there a command like

usr_vars()

which would show

a=5
b=7
c=9

????

I tried globals(), locals() and vars(), but they all mix my user-defined
variables with system ones... clues? ideas?

thanks in advance,

Pier

Jul 18 '05 #1
1 2738
>>>>> "user" == user <us**@domain.invalid> writes:
user> I tried globals(), locals() and vars(), but they all mix my
user> user-defined variables with system ones... clues? ideas?

These are the right functions to be thinking about. If I may be so
bold, perhaps you are not asking the right question. What is it you
need to do? You say you want to get the user defined variables. To
what end? Perhaps if you describe what it is you need to do, not how
you plan to do it, someone can offer an insightful solution.

Barring that, would it be helpful to remove the system/module vars by
first saving the keys of locals before user input, eg

from os import * # import a bunch of non user-defined names for testing

def diffkeys(k1, k2):
"return the keys in d1 that are not in d2"
k2d = dict( [(k,1) for k in k2] )
return [k for k in k1 if not k2d.has_key(k)]

def items_for_keys(keys, d):
"return a list of (k,v) pairs for given keys in dict d"
seen = dict( [(k,1) for k in keys] )
return [ (k,v) for k,v in d.items() if seen.has_key(k)]

base = locals().keys()
#now come the user vars
x = 1
y = 2
new = locals().keys()
new.remove('base') #a user var we aren't interested in
print items_for_keys(diffkeys(new, base), locals())
JDH

Jul 18 '05 #2

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

Similar topics

6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
9
by: jsale | last post by:
Hello, I am having a problem with multiple users using my asp.net application - namely that if each user clicks save at the same time, some, or all, of the users crash out. Do I need to do...
3
by: Sandy | last post by:
Hello - There is a possibility of having Panel1 displayed, Panel1 and Panel 2 displayed or Panel1, Panel2 and Panel3 displayed. When a user clicks on a Button, those Panels, if visible, are...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
1
by: David Hearn | last post by:
I am creating a user control for use on several of my pages. I have some variables that are set on my pages where the user control will be used. I need my user control to automatically be able to...
9
by: David | last post by:
With a non-server app there is one instance of the program running and one user 'using' it at a time. With this scenario I'm pretty comfortable with variable scope and lifetime. With a server app...
5
by: Andy | last post by:
I have an admin section of my asp.net 2 application, and I want to be able to automatically login as a different user (Forms Authentication) whilst keeping my current session going too. The problem...
1
by: chowdary | last post by:
hi, when the user clicks the logout.php the session variables are destroying. my doubt is when the user clicking back, again they are entering into the pages. how to check whether session...
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
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
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
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
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.