Python Forum
Global Variables. Migrate code from MatLab
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global Variables. Migrate code from MatLab
#9
(Jan-12-2017, 04:35 PM)micseydel Wrote:
(Jan-11-2017, 11:07 PM)Felipe Wrote: You can give me a short example from what you mean with "import the variable into the other file"? It's different from use arguments into functions?
They are different, but looking more closely, you can't do it because the files would have to import from each other.

Is I a variable or a constant? Things are hairy if it's a variable. If it's just a constant, you can keep it in a separate file for constants if it's needed by multiple things (or needs to be easy to change) and if it's just needed in one place, that's probably where it should live unless there's a good reason to put it somewhere else.

Hi,

The values are constants. Some like I are constants with integer values, others are vectors with N positions and float values.
For example, I = 90 is a constant that means the inclination of the magnetic field in degrees, X = 1, 1.2, 1.4, 1.6, 1.8... is a vector with positions of measure in kilometers.

If I can write something like a function or structure, which I can call in the main program to access the values and do the math that I need, it's fine.

The problem of use arguments is because some functions call another functions. It obligate me to write functions that have many arguments. I'm concerning about the efficiency too, because my program invert a problem with many dimension using PSO. So the computational cost can be a problem.
Reply


Messages In This Thread
RE: Global Variables. Migrate code from MatLab - by Felipe - Jan-13-2017, 01:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand global variables 357mag 5 1,122 May-12-2023, 04:16 PM
Last Post: deanhystad
  Global variables or local accessible caslor 4 1,029 Jan-27-2023, 05:32 PM
Last Post: caslor
  global variables HeinKurz 3 1,151 Jan-17-2023, 06:58 PM
Last Post: HeinKurz
  Clarity on global variables JonWayn 2 949 Nov-26-2022, 12:10 PM
Last Post: JonWayn
  migrate code from tkinter to pygame Frankduc 16 3,154 Jun-01-2022, 12:45 PM
Last Post: Frankduc
  Global variables not working hobbyist 9 4,740 Jan-16-2021, 03:17 PM
Last Post: jefsummers
  Global vs. Local Variables Davy_Jones_XIV 4 2,656 Jan-06-2021, 10:22 PM
Last Post: Davy_Jones_XIV
  Global - local variables Motorhomer14 11 4,264 Dec-17-2020, 06:40 PM
Last Post: Motorhomer14
  Question regarding local and global variables donmerch 12 5,105 Apr-12-2020, 03:58 PM
Last Post: TomToad
  local/global variables in functions abccba 6 3,447 Apr-08-2020, 06:01 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020