2,646 Posted Topics
Re: The description is not clear at all. We need a [minimal working example](https://en.wikipedia.org/wiki/Minimal_Working_Example): a *small* json object, and a short piece of code which raises the described exception (ValueError ...). You can add the expected result. | |
Re: > also, how could I lower the quality of a float who's mantissa is bigger than 16 bits A normal float is written on 64 bits, with 1 sign bit, 11 exponent bits and 52 mantissa bits. Why don't you convert it to a shorter ieee format ? It seems … | |
4 hours after [my last post](https://www.daniweb.com/software-development/python/threads/497125/python-program-crashes-after-using-too-much-memory#post2175367) in [this thread](https://www.daniweb.com/software-development/python/threads/497125/python-program-crashes-after-using-too-much-memory), the python forum page says that the post was written by Raisefamous. I tried to empty my browser's cache (qupzilla in linux), but it didn't work. It is obviously a bug. | |
Re: All the `del` statements are useless: local variables in functions are destroyed when the function exits. Without running the code, I see only one growing structure: the array `cointegratedPairs`. This is the most probable source of memory leak. | |
Re: Hi. Here is a small experiment in the python console >>> "python.exe".rsplit('.', 1) ['python', 'exe'] It should be easy now ! | |
Re: One part of the problem is that we don't know which command or (python?) statement fails to read the entire file. Can you describe more precisely where it fails. | |
Re: nice, it looks like a kind of 'scanf' for python. ![]() | |
Re: I think you should definitely separate read and write. Start with a function that reads the json file and generates tuples such as ('Fee', 5, '1/1/0001 12:00:00 AM') Use the `yield` statement to generate the tuples, and don't worry about the types, they can be post-processed. Your generator may generate … | |
Re: It is because temp is a string (`str` type) while 85 is an integer. Integer comparison is different from string comparison (string ordering is lexicographic order). You should do temp = int('32') to convert to int for example. This problem does not exist in recent versions of python where comparison … | |
Re: I think it works only with recent versions of python. For me, it works with python 3.4 but not with 2.7. Edit: you can write for rec in records: tag, args = rec[0], rec[1:] | |
Re: Interesting. It can be improved by using the standard modules argparse for command line parsing and subprocess to get output and error from called commands. | |
Re: It looks like homework. Did you try to add the polynomials in a python console ? | |
Re: Hm, you want to understand some basic things in programming, but the task of converting markdown to html is not such a basic thing. I would recommend it only to experienced programmers. Such modules already exist: you can install the [markdown module](http://pythonhosted.org/Markdown/install.html), then use its conversion function [described here](http://pythonhosted.org/Markdown/reference.html) import … | |
Re: If this is a question in the python programming forum, you could start reformulating the problem by introducing your program. What should your program do ? How will it read the sensors values, how does it now the distance between the two sensors ? What should it do with the … | |
Re: The code finds the lines containing the word `'python'` in the file named `'history'`. The search function yields the line containing that word and a deque of at most five lines immediately before that line. For example if the file contains foo bar baz qux spam eggs ham my python … | |
Re: I've always found the threading module easier when Condition instances are used. Here is a periodic timer implemented with a condition: from __future__ import print_function import datetime as dt import threading as th import time class PeriodicTimer(th.Thread): def __init__(self, delay): th.Thread.__init__(self) self.locked = th.Condition() self.delay = float(delay) assert self.delay > … | |
Re: When `[x * 3 for x in range(2, 10, 2)]` is evaluated as a result of the input function, the variable `x` takes the values `2, 4, 6, 8`. When the `x` is printed, its value is the last one, `8`. You can avoid this by using another variable name. … | |
Re: You can use the datetime module for these calculations. According to this module however, 12:00PM is at noon and 12:00AM is at midnight: >>> import datetime as dt >>> fm = '%I:%M%p' >>> def change(s): ... t = dt.datetime.strptime(s, fm) + dt.timedelta(days=36524) ... return (t - dt.timedelta(minutes=30)).strftime(fm) ... >>> change('12:00AM') … | |
Re: > a way to R-shift Value by the binary size of the data field I don't understand what you want to do. What is the *binary size of the data field* ? Can you give examples of input values and expected output values ? | |
Re: Here is a way. I replaced all the print statements by calls to a function `printout()`. This function is built by using the `print_function` feature which makes python 2 look like python 3. Note that you can still use print in other parts of the code but with a function … | |
Re: > decorators only work on function call, not on definition On the contrary, the decorator is called once, immediately after the function's definition >>> def deco(f): ... print f.__name__, 'is being defined' ... return f ... >>> @deco ... def foo(x): ... return x * x ... foo is being … | |
Re: We don't know which string you are evaluating; can you add raise RuntimeError(repr(Evaluar.funcion)) immediately before `fa = eval(...` and post the error output ? | |
![]() | Re: The documentation appears to live [here](http://swingtime.readthedocs.org/en/latest/index.html). I think you want something impossible. There is nothing about allowing a foreign key in an event (apart from the event type). The only field allowing you to connect the event to anything else is the Note field, which permits to store a string. ![]() |
Re: The file is probably not yours, or has wrong permissions. Open a terminal and type `ls -l file.php` to see the permissions. Post the result here. | |
Re: I'm afraid the indention didn't make it through the web editor. The best way to indent python code is with 4 space characters such as in if x == 0: print("hello") # <- see the 4 space at the beginning ? It means that you must configure your editor so that … | |
Re: This code is very difficult to understand. The first healthiness rule is that if a variable name is set in a loop condition, such as `pos_X` or `prog_id` in for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width): then the same variable must not be redefined inside the body … | |
Re: Replace `+''+` with `,`. Why didn't you use `next(iter(...))` as I told you ? | |
Re: There is no fundamental difference between 5 years or 5 seconds from a computer's point of vue. | |
Re: > I wonder if there is a way in Python to simply import everything? There is a mechanism in the [py library](https://pypi.python.org/pypi/py): a [mapping](http://pylib.readthedocs.org/en/latest/misc.html#mapping-the-standard-python-library-into-py) of the standard library. With this, you can avoid importing modules explicitely, for example >>> import py >>> py.std.ttk.Frame <class ttk.Frame at 0x7f669a13a7a0> >>> py.std.hashlib.sha256 <built-in … | |
Re: It probably means that `ch` is a module, and that there is no variable named `RoomManager` in this module. Try to write print(ch) before `class Yakudi`, to see what `ch` really is. | |
Re: It means that `cfg.project["phenotype"][0]` is a dictionary with a single key and you only want to print the key. You can get a key from a non empty dictionary with `next(iter(dictionary))`. So I suggest d = cfg.project["phenotype"] print("-L", next(iter(d[0])), next(iter(d[1]))) Of course, if there are more than 1 key in … | |
Re: `dict.iteritems()` [disappeared from python](https://docs.python.org/3/whatsnew/3.0.html?highlight=iteritem#views-and-iterators-instead-of-lists) in python 3.0. Use `dict.items()` in python 3, which returns a [*view*](https://docs.python.org/3/library/stdtypes.html?highlight=items#dict-views) (in python 2, `dict.items()` used to return a list). | |
Re: `touch foo` creates file `foo`, if that's what you mean, but I probably missed something in your question. (?) | |
Re: The problem is not with the plotting, there are very good libraries for plotting such as matplotlib or pyqtgraph or perhaps the gr framework, etc. The problem is rather that you're obtaining your numerical data from a R library (bioconductor, commeRbund etc), so you will need a way to access … | |
Re: The first grain is missing in `grains_sum`. The result is `2**65-1`, an odd number. | |
Re: > By default open() uses the ASCII encoding According to the documentation, the default encoding is `locale.getpreferredencoding()`. For me it is >>> import locale >>> locale.getpreferredencoding() 'UTF-8' You can try to guess your file's encoding with the [chardet](https://pypi.python.org/pypi/chardet) module/cli utility. | |
Re: A possibility is to use an `array.array` instead of a `list`. It is a little slower but it takes about 8 times less memory. #!/usr/bin/env python3 # -*-coding: utf8-*- '''Compares Sieves of Eratosthenes with list or array implementation ''' from array import array ### Vegaseat code to time the function … | |
Re: At first sight, it seems that you are trying to do some unpythonic design. I'd like to have the code of class `struct`. Is it an ordinary user defined class or something else ? Also I don't understand this data = x() # read data from imported file If x … | |
Re: Instead of if ... if ... if ... else ... use if ... elif ... elif ... else ... If you need to go to the next iteration of a while loop, you can use a continue statement. | |
Re: I suggest to prepare a pattern once for all and then to trucate it for a given W # -*- coding: utf-8 -*- # first prepare 5 long lines with 100 unicode characters each dic = {'a': u'\u2591', 'b': u'\u2588'} data = ['aaaa', 'aaab', 'baba', 'abaa','aaaa'] data = [''.join(dic[x] for … | |
Re: I don't think it can be reduced significantly. Why do you want a shorter code ? | |
Re: Instances don't use less memory if the method is defined outside the class definition. Instances don't keep pointers to the method. They only keep a pointer to the class, which in turns keeps a pointer to the method. If you want, you can add the function to the class after … | |
Re: It is a rather unusual first post. How could anybody have abused you as you joined 30 minutes ago ? | |
Re: Hi. Use module binascii >>> from binascii import unhexlify >>> s = 'f0cbf260e0ca8ec2431089fb393a1c29513aaaa5847d13e8be84760968e64dc6' >>> t = unhexlify(s) >>> t '\xf0\xcb\xf2`\xe0\xca\x8e\xc2C\x10\x89\xfb9:\x1c)Q:\xaa\xa5\x84}\x13\xe8\xbe\x84v\th\xe6M\xc6' | |
Re: You can start with computing the term frequencies for each term and every document. There is a snippet by Vegaseat [Click Here](https://www.daniweb.com/software-development/python/code/462632/word-frequency-count-revisited-python) Once you have these frequencies, [wikipedia](https://en.wikipedia.org/wiki/Tf–idf) has various formulas. | |
Re: [QUOTE=python1;1022601]How can we save a text file we make using python in another directory?The default directory is always the directory in which , the program is ? is there any way to change this?Can this be done when we are creating the file (FILE=open(filename,"w")) thanks in advance[/QUOTE] Instead of filename, … | |
Re: I think your data is not valid python code. For example to read the hindi part, I had to replace all the \N with \ \N (double backslash) otherwise python would not read the unicode string. Here is what I get when I print the hindi part: ताजा\JJ साँसें\N_NN और\CC_CCD … |
The End.