python-import

How to prevent a race condition when multiple processes attempt to write to and then read from a file at the same time

ε祈祈猫儿з 提交于 2019-12-29 07:48:16
问题 I have the following code (simplified for clarity): import os import errno import imp lib_dir = os.path.expanduser('~/.brian/cython_extensions') module_name = '_cython_magic_5' module_path = os.path.join(lib_dir, module_name + '.so') code = 'some code' have_module = os.path.isfile(module_path) if not have_module: pyx_file = os.path.join(lib_dir, module_name + '.pyx') # THIS IS WHERE EACH PROCESS TRIES TO WRITE TO THE FILE. THE CODE HERE # PREVENTS A RACE CONDITION. try: fd = os.open(pyx_file,

Difference between Numpy and Numpy-MKL?

喜你入骨 提交于 2019-12-29 07:32:11
问题 I wanted to test some signal processing and statistics using SciPy. So I had to use scipy.signal and scipy.stats , but I always used to get an error: ImportError: DLL load failed: The specified module could not be found. I was using Numpy 1.7.1, scipy 0.12 and Python 2.7.3. I checked on the internet and asked about it on other forums too! This problem got solved when switched my Numpy distribution with the Numpy-MKL distribution. I want to know the difference between the two libraries ? 回答1:

Difference between Numpy and Numpy-MKL?

删除回忆录丶 提交于 2019-12-29 07:31:20
问题 I wanted to test some signal processing and statistics using SciPy. So I had to use scipy.signal and scipy.stats , but I always used to get an error: ImportError: DLL load failed: The specified module could not be found. I was using Numpy 1.7.1, scipy 0.12 and Python 2.7.3. I checked on the internet and asked about it on other forums too! This problem got solved when switched my Numpy distribution with the Numpy-MKL distribution. I want to know the difference between the two libraries ? 回答1:

Import a Python module into a Jinja template?

北战南征 提交于 2019-12-29 02:54:33
问题 Is it possible to import a Python module into a Jinja template so I can use its functions? For example, I have a format.py file that contains methods for formatting dates and times. In a Jinja macro, can I do something like the following? {% from 'dates/format.py' import timesince %} {% macro time(mytime) %} <a title="{{ mytime }}">{{ timesince(mytime) }}</a> {% endmacro %} Because format.py is not a template, the code above gives me this error: UndefinedError: the template 'dates/format.py'

What's the correct way to sort Python `import x` and `from x import y` statements?

和自甴很熟 提交于 2019-12-29 02:20:29
问题 The python style guide suggests to group imports like this: Imports should be grouped in the following order: standard library imports related third party imports local application/library specific imports However, it does not mention anything how the two different ways of imports should be laid out: from foo import bar import foo There are multiple ways to sort them (let's assume all those import belong to the same group): first from..import , then import from g import gg from x import xx

Import statement works on PyCharm but not from terminal

一个人想着一个人 提交于 2019-12-28 14:01:11
问题 Pycharm 2016.2.3, Mac OS X 10.11.1, Python 3.5 (Homebrew); I have this folder structure project /somepackage /subpackage __init__.py bar.py __init__.py foo.py foo.py: import somepackage.subpackage.bar print("foo") bar.py: print("bar") So my expected output is bar foo This works fine when run from PyCharm. However, when I run it from my terminal I get an ImportError: $ pwd $ /home/project (not the actual path; just omitting some personal stuff) $ python3.5 somepackage/foo.py File "foo.py",

Cython package with __init__.pyx: Possible?

我怕爱的太早我们不能终老 提交于 2019-12-28 12:18:15
问题 Is it possible to create a Python 2.7 package using __init__.pyx (compiled to __init__.so )? If so how? I haven't had any luck getting it to work. Here is what I have tried: setup.py : #!/usr/bin/env python from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext foo = Extension(name='foo.__init__', sources=['foo/__init__.pyx']) bar = Extension(name='foo.bar', sources=['foo/bar.pyx']) setup(name='foo', packages = ['foo'], cmdclass={

Cython package with __init__.pyx: Possible?

我怕爱的太早我们不能终老 提交于 2019-12-28 12:18:09
问题 Is it possible to create a Python 2.7 package using __init__.pyx (compiled to __init__.so )? If so how? I haven't had any luck getting it to work. Here is what I have tried: setup.py : #!/usr/bin/env python from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext foo = Extension(name='foo.__init__', sources=['foo/__init__.pyx']) bar = Extension(name='foo.bar', sources=['foo/bar.pyx']) setup(name='foo', packages = ['foo'], cmdclass={

How to unimport a python module which is already imported?

◇◆丶佛笑我妖孽 提交于 2019-12-28 05:17:04
问题 I'm quite new with NumPy/SciPy. But these days, I've started using it very actively for numerical calculation instead of using Matlab. For some simple calculations, I do just in the interactive mode rather than writing a script. In this case, are there any ways to unimport some modules which was already imported? Unimporting might not needed when I write python programs, but in the interactive mode, it is needed. 回答1: There's no way to unload something once you've imported it. Python keeps a

Importing modules in Python - best practice

落花浮王杯 提交于 2019-12-28 04:54:13
问题 I am new to Python as I want to expand skills that I learned using R. In R I tend to load a bunch of libraries, sometimes resulting in function name conflicts. What is best practice in Python. I have seen some specific variations that I do not see a difference between import pandas , from pandas import * , and from pandas import DataFrame What are the differences between the first two and should I just import what I need. Also, what would be the worst consequences for someone making small