other:python:misc_by_jyp
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
other:python:misc_by_jyp [2022/12/12 14:50] – Improved by changing the sections' levels jypeter | other:python:misc_by_jyp [2022/12/12 15:24] – Added the global variables section jypeter | ||
---|---|---|---|
Line 43: | Line 43: | ||
===== Playing with strings ===== | ===== Playing with strings ===== | ||
- | ==== Filenames, etc... ==== | ||
- | Check [[other: | + | ==== Splitting |
- | + | ||
- | ==== Splitting strings ==== | + | |
It's easy to split a string with multiple blank delimiters, or a specific delimiter, but it can be harder to deal with sub-strings | It's easy to split a string with multiple blank delimiters, or a specific delimiter, but it can be harder to deal with sub-strings | ||
Line 257: | Line 254: | ||
Note: a configuration file is also a way to easily store and exchange text data ! | Note: a configuration file is also a way to easily store and exchange text data ! | ||
+ | |||
+ | ===== Working with global variables ===== | ||
+ | |||
+ | There is a good chance you don't actually want/need a //global// variable. Be sure to use the '' | ||
+ | |||
+ | * [[https:// | ||
+ | * Simple module example\\ < | ||
+ | |||
+ | def set_myvar(new_val): | ||
+ | # Note: need to explicitly define a global variable (of a module) | ||
+ | # as ' | ||
+ | # Otherwise, the value will not be REdefined outside the function | ||
+ | global _myvar | ||
+ | _myvar = new_val | ||
+ | |||
+ | def get_myvar(): | ||
+ | return _myvar | ||
+ | |||
+ | def myfunc(nb_repeat = 10): | ||
+ | print(nb_repeat * _myvar)</ | ||
+ | * [[https:// | ||
===== Sorting ===== | ===== Sorting ===== | ||
other/python/misc_by_jyp.txt · Last modified: 2024/11/04 15:01 by jypeter