These are chat archives for ipython/ipython

5th
Jul 2016
Konstantin Parashchevin
@CrownID
Jul 05 2016 13:33
Hi! Please someone help me.
Why i can't get access to variables in main method after loading mymodule.py through %load
i use ipython 2.7 on my centos machine
Min RK
@minrk
Jul 05 2016 13:39
@CrownID can you provide more information?
what code are you trying to run? How are these variables defined, and where are you trying to access them?
Konstantin Parashchevin
@CrownID
Jul 05 2016 13:47

@minrk
code like this
```def ipcheck(ipstr):

<skip>

def readToDict():

<skip>

def main():
stat = []
cl = readToDict()
test = 1
for i in cl['ip']:
cstat = ipcheck(i)
print(i + " : " + cstat)
stat.append(cstat)

    print(stat)

```

oops(
load this file %load /home/user/projects/netdiag/netresponse.py
Min RK
@minrk
Jul 05 2016 13:50
You want the ``` on their own line
and what variables are you trying to access?
Konstantin Parashchevin
@CrownID
Jul 05 2016 13:52
i trying print stat and test) but
```NameError: name 'test' is not defined
Min RK
@minrk
Jul 05 2016 13:52
those variables are defined inside the main function, so they will only be available inside the main function
If you want to make variables available outside a function, you must return them or declare them as global.
Konstantin Parashchevin
@CrownID
Jul 05 2016 13:57
ou thnx a lot! i'm beginner in python)
chizou
@chizou
Jul 05 2016 21:53
does anyone know if it's possible to make jupyter notebook write to a database instead of writing to disk?
Jason Grout
@jasongrout
Jul 05 2016 21:56
yes
You'd have to write a new Contents manager on the server side.
IIRC, Quantopian implemented one that writes to a Postgresql database, for example.
chizou
@chizou
Jul 05 2016 21:57
that seems pretty involved
Jason Grout
@jasongrout
Jul 05 2016 21:58
depending on how comfortable you are with writing the python code and databases, it could be, or it could be pretty straightforward
chizou
@chizou
Jul 05 2016 21:59
got it. i think it's outside of the scope of my current project... but who knows, management might decide it is within scope
thanks for the help
chizou
@chizou
Jul 05 2016 22:00
awesome, thanks!