471,305 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Use variable after use on function

Hi everybody !
Currently i have a problem about 10 code lines on my mass mailling script
Expand|Select|Wrap|Line Numbers
  1. min_id = 0
  2. max_id = 99
  3.  
  4. while max_iduser[0] >= min_id:
  5.  
  6.     recup_mail(min_id ,max_id)
  7.  
  8.     min_id += 100
  9.     max_id += 100
  10.     time.sleep(30)
  11.  
  12. else :
  13.     sys.exit()
  14.  
  15.  
My problem is after use recup_mail(...), min_id and max_id have a variable type like NULL
Can you tell me how i can increment the both variable
Thanks !
Nov 3 '07 #1
1 962
bartonc
6,596 Expert 4TB
If it were a function call, it would look like this:
Expand|Select|Wrap|Line Numbers
  1. def MassMail(whatever):
  2.     global min_id, max_id
  3.     # code that changes values here
  4.  
  5. # changed "global" variable may be used here
Although the use of globals is highly discourage. The best way is to return them from the function that changes them:
Expand|Select|Wrap|Line Numbers
  1. def MassMail(min_id, max_id):
  2.     min_id += 100
  3.     max_id += 100
  4.     return min_id, max_id
  5.  
  6. min_id, max_id = MassMail(0, 100)
  7. print min_id, max_id
This reduces errors by making changed in variables close to where they are assigned.
Nov 3 '07 #2

Post your reply

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

Similar topics

7 posts views Thread by Klaus Johannes Rusch | last post: by
3 posts views Thread by Grant Wagner | last post: by
3 posts views Thread by Datta Patil | last post: by
23 posts views Thread by Russ Chinoy | last post: by
pbmods
1 post views Thread by pbmods | last post: by
2 posts views Thread by Florian Loitsch | last post: by
reply views Thread by rosydwin | last post: by

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.