Categories

Categories

 
 

Twitter

Twitter: @CK2go (Carsten König: Python, Astronomy, Softwaredesign)

CK2go on Twitter: @CK2go

 
 
02.12.2019
09:32

Globals are not global in Python

Well, the title already says it. Globals are module wide, not global global.... This means, that if you do

 
 
from module_b import doSomethingWithGlobalA
 
global a
a = 10
doSomethingWithGlobalA() # e.g. global a; a += 5;
 
print(a)
# a is still 10
 
 

The global would not change. This is because the global keyword only makes variables accessible to the module level - not beyond.

So if you instead of importing the module execute the file, it will run in the same context of the script calling it:

 
 
execfile('module_b.py')
 
global a
a = 10
doSomethingWithGlobalA() # e.g. global a; a += 5;
 
print(a)
# a is now 15
 
 

This will execute the files instructions in the local context and will work as (naively) expected.

To avoid confusion: best is to never mess with globals anyways... Global state is in general considered bad practice (for several reasons).

 
 
08.06.2017
17:08

Eclipse/Texlipse: bibtex file in different directory

I recently ran into the problem that I have a common library where i store all my Bibtex references, but Eclipse/Texlipse refused to find it, although I linked the library file from within the project folder.

The solution is rather simple, as it just requires setting the BIBINPUTS evironment variable, so Bibtex can find the desired *.bib file at the different location.

To do so in Texlipse, go to Preferences->Texlipse->Builder Settings->Environment. There you hit 'New...', enter 'BIBINPUTS' as the key and the directory where the bibtex library file (i.e. your *.bib file) is located as the value. Hit OK, close the preferences screen and you are set.

Hope that helps.

 
 
21.03.2017
13:14

Eclipse/Subversive: DH keypair issues

I recently had the issue that one of the SVN servers that I regularly use refused to connect anymore. In the command line, everything wored as intended, but using Subversive within Eclipse did not work. I got a popup window, containing the following information:

java.lang.RuntimeException: Could not generate DH keypair

The problem was, that the SVN server no longer accepted the standard Diffie-Hellman algorithm for SSL connections, as it is supposedly insecure.

The solution is to disable the standard Diffie-Hellman algorithm. To do so a single line needs to be added to the java.security configuration file (for my Oracle Java installation it is found at /opt/Oracle_Java/jdk1.8.0_121/jre/lib/security/) - I just added the following line at the end of the file:

jdk.tls.disabledAlgorithms=DH

Make sure that your Eclipse installation is using the right Java installation though. This can be configured in the eclipse.ini (my one has the vm set explicitly):

-vm
/opt/Oracle_Java/jdk1.8.0_121/jre/bin/

Hope this helps someone! ;)

 
 
25.09.2013
16:03

Python autocompletion in VIM

Having autocompletion (and some other nice stuff) for Python in VIM is not only a nice feature, but something allowing you to be more efficient when programming Python.

First see the result:

Youtube: http://www.youtube.com/watch?v=TNMjbaimk9g


To make the functionality (and color scheme) available, download the tarball (pythonVim.tar.gz) and extract it in your home directory (i.e. /home/your_user_name), execute the installPythonVim.sh file to install the neccessary plugins (make it executable first, e.g. by chmod u+x installPythonVim.sh), and add the content of the .vimrc to your .vimrc file. Next time you start VIM, you should have autocompletion available...

Requires VIM 7.3 or above (check with vim -version). You can get this from the VIM FTP archive at ftp://ftp.vim.org/pub/vim/unix/. Download the archive and extract it, then do the following to install in the local users home directory with Python support enabled:

./configure --with-features=huge --enable-pythoninterp --prefix=$HOME
make all install

Make sure to add $HOME/bin to your $PATH, so the right vim is picked.

 

Source: http://www.lykostech.net/using-vim-as-python-ide/

 
 
22.07.2013
16:22

Linux: use SSH with X11 forwarding and compression for better performance

To get better performance when using X11 forwarding (either with the -X or -Y option) with a SSH connection, one should enable data compression:

$ ssh -X -C -c blowfish-cbc,arcfour user@your.host.com

to avoid enabling compression with each command, one could enable it permanently in the configuration file ($HOME/.ssh/config):

 

 

 

  1.  
  2. Cipher blowfish
  3. Ciphers blowfish-cbc,aes128-cbc,3des-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc
  4. Compression yes
  5.  

 

 

 

This would allow creating the compressed SSH connection simply through

$ ssh -X user@your.host.com

 
 
 
 
Impressum