New answers tagged

0

No, bytecode files do not contain mnemonics. Mnemonics are textual representations for instructions of a (virtual/bytecode) processor and are an integral part of assembly languages. Bytecode files are not meant to be read by humans and thus are typically binary files that directly contain the machine-code (binary) instructions for the bytecode processor.


-2

A long time to think about this. To day , i found the way . i don't know it is the best way. you create a file with the name: conn.py , and save it in /usr/local/lib/python3.5/site-packages/conn/ folder. I use freebsd and this is the path of my site-packages folder. in my conn.py: conn = "dbname=omnivore user=postgres password=12345678" `````````````````````...


0

So, it sounds like you want something relatively fluid. If yesterday was a snow day you could add it the day after and then rerun calculations to look at the workloads (theoretically) required to meet deadlines. Just thinking on the fly here: Jobs: Job ID, Name, Start Date, End Date Depts: Dept ID, Name, WeekType JobHours: Job ID, Dept ID, Allotted Hours ...


-1

The solution to my problem was as simple as adding on & to the end of each line. For example, os.system("./workspace/eclipse/eclipse &")


0

If you just want to launch the commands, you don't need Python for that. A simple Bash script is largely enough. Notice the & at the end of every line. workspace/eclipse/eclipse & ../../usr/bin/jvisualvm & docker-compose -f s3_dynamodb.yml up & If, for some reason, you can't use Bash, then Python can actually do that too with POpen: ...


0

It's not about testing, it's about tuning. Since you're doing a lot of I/O, any sort of "CPU profiler" is not what you want. The method I always use is this. Here's what I would do if I were you: Tune the program until it is as fast as possible. Then if it is not fast enough to be satisfactory, get faster hardware. The way I would do it is take a number of ...


3

After doing some legwork, downloading the last package that was available for the library the only licensing information I found was in the PKG-INFO file: License: PSF or ZPL Which makes me believe you can choose either. After 10 years of neglect, efforts to contact the author may not go well, but it's worth attempting any obvious action you can. ...


0

If speed is the issue, and you only need NumPy (not SciPy or Matplotlib), try PyPy. It has a JIT that is very powerful. If you don't need to use Python, try Julia. Julia was designed to be fast — and so it is fast. For example, a typical loop in Julia compiles (via LLVM) to code that is the same (bar bounds checks) as what a C or Fortran compiler would ...


1

... perhaps there would be issues that would take time to resolve Most certainly there would be issues. Python is a general purpose language. Matlab is specialized. This keeps you out of the weeds. Sure you can't wander off anywhere you want but that is what keeps things moving. There may be many Python libraries that approximate what matlab does to ...


0

How do I know if my code is running fast enough? That very much depends on your use case -- your program runs for 1.4 hours which might or might not be fast enough. If this is a one-time process 1.4 hours is not that much - spending any time on optimization is hardly worth the investment. On the other hand, if this is a process that should run e.g. once ...


0

As others have noted, don't optimize unless the speed is unsatisfactory. You've moved on to the next step which is to profile. Once you've profiled its time to look for possible optimization candidates: Looking at your process which runs for 528 seconds. You have one call to OBSparser.py:48(parse) using 166 seconds. If you could totally eliminate ...


1

This is what non-functional requirements of performance are for. The notion of fast enough has nothing technical per se. It depends on user perception of your product, and should be translated through the requirements. This is the only objective way for you to tell whether your actual implementation is fast enough or not. If you don't have those ...


1

You have forgotten the most basic question: Is the speed satisfactory for the use case? If the answer is "yes" -> don't profile If no, you might look at your table. But honestly, it looks not terribly useful, because almost all time is spend in OBSparser.py:48(parse), which takes a LONG time. I would suggest you refactor that method into several ...


-1

try this in a new interpreter C:\tools\python-2.7>python Python 3.5 (default, july 15 2016, 09:23:32) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import sys print '\n'.join(sys.path) C:\tools\python-3.5\lib\site-packages\pyreadline-2.0_dev1-py3.5-win32.egg C:\...


5

There's a couple of ways you can do this: You can use isinstance to determine what the object's class is: if isinstance(foo, bar): do_something() elif isinstance(foo, baz): do_something_else() else: default_behavior() However, this gets unwieldy quickly with a large number of possible classes, and isn't good OOP. The OOP way would be to use ...


1

This is the difference between an immutable object (as Python numbers are) and a mutable object (as Numpy matrices are). When you perform an operation on an immutable object, a new copy is made, and your variable is updated to refer to the new copy: x = 0 ... x = 7 First a '0' object is created, and 'x' is set to refer to it. Then a '7' is created, and '...


1

This applies to any language. If you don't plan on doing anything with the exception, or as a result of the exception being caught, then don't bother catching it. It saves you a few lines of code and indentation. Seeing an except block could tell other programmers, who are busy and aren't reading every line of code, "Oh good. CrazyPython is handling this ...


-1

actually, it isn't about programming style, is and == are very different: the is operator checks if the two items reference the same object the == operator checks if the objects that the two items reference are the identicle for example: l = [1,2,3,4,5,6,7,8,9,1,2,3,4,] l2 = l # make ir reference the object that l references l3 = l[:] # ...


2

According to the Classes section of the Python docs: “Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a ...


1

Don't get too caught up with the way things are usually done, an API can be restful without having to have resource identifier specified in the URL. In your case I would say its perfectly acceptable to place the path(s) in the POST body.


0

I've managed to paralellize it using GNU Parallel. Firstly, I had to make a slight changes to the script - I had to make sure that only the "file" part will use seek to restart file pointer(you can't seek on pipe). I also had to use this hack to get utf8 stdout/stdin: reload(sys) sys.stedefaultencoding('utf8') After that, I was ready to call the script: ...


0

There are packages (your type 1), and packages with added files (setup.py) in order to distribute through PyPI (your type 2). Both are packages and should follow the naming convention for packages, meaning lower-case for the package name. About the Jinja2 example: the file name on PyPI for Jinja2 starts with a capital: "Jinja2-2.8.tar.gz". But after ...


7

While Python's current implementation (which lacks a lot of the optimisations performed by other dynamic languages, e.g. modern Javascript implementations and, as you point out, Lua) is a source of most of its problems, it does have some semantic issues that would make it difficult for an implementation to compete with other languages, at least in certain ...


17

What semantic features of Python (and other dynamic languages) contribute to its slowness? None. Performance of language implementations is a function of money, resources, and PhD theses, not language features. Self is much more dynamic than Smalltalk and slightly more dynamic than Python, Ruby, ECMAScript, or Lua, and it had a VM that outperformed all ...


0

You can use the concept of a connection object (similar to how database driver libraries work) . Your API clients will instantiate your QueryAPI object once passing the clientid and secret. client = QueryAPI(clientid, clientsecret) user = User(name, address) client.create_user(user) If your data model objects can in turn own child objects it might be ...


1

If you want to get real CPU parallelization as Mason stated you need to get around GIL by forking instead of using threads. This has extra overhead compared to threads but it may work if the process time is the bottleneck. The best way to achieve this in a non-hacky way is to use multiprocess.Pool and use a variant of map. This will dispatch your iterable ...


1

A sentinel and a defaulted arg is a good way to do it. I would use an arbitrary object though, not a list (preference, and this way someone won't go about fiddling with it). class A(object): _DEFAULT = object() def __init__(self): self._size = 0 def sizeC(self, arg=_DEFAULT): if arg is not DEFAULT: self._size = arg ...


0

Probably not. Python has what's known as a Global Interpreter Lock that ensures that the interpreter is never running on more than one thread of a process at a time. This means that, unless your processing is making very heavy use of native code processing such as NumPy that spends most of its time outside of the interpreter, it is impossible to speed it ...


2

If you indeed want other developers to work on the actual code, then yes, source control is the solution. If you want control over what goes in, then indeed PR's seem like the correct choice. If you use GitHub you can provide comments before merging a PR


3

I am assuming you are aware of Python's built-in sort and are simply asking this as a learning exercise. (If you just want to use the 'best' sort, use Python's built-in sort function. It is heavily optimised and will be faster than anything you implement in Python.) The short answer is, your quicksort function has a bug, and if you fix it then it will work ...


2

No. The key word here is "nonexclusive" license. It means that you're granting them the right to distribute your code, (which is the entire point of putting it up on a package manager,) without setting up any sort of exclusive deal or transfer of rights with them. And as the license is to distribute your code, rather than to use it, it doesn't conflict ...


0

In the interest of making information available to anyone in the future, my current solution is having a socket.io server running, which connects over a socket to a python script. the socket.io server just relays information between the two and is capable of handling multiple clients whereas a python only solution would not handle multiple clients without me ...


0

UPDATED ANSWER The best way I've found to control a looping script in Heroku is by defining a process type for the script in the Procfile. This way, you simply have to scale the number of dynos for the process type to 1 and 0 to start and stop the script, respectively. So for a process type named "run": Start the script heroku ps:scale run=1 Stop the ...



Top 50 recent answers are included