2,646 Posted Topics

Member Avatar for Saran_1

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.

Member Avatar for Saran_1
0
2K
Member Avatar for Tcll

> 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 …

Member Avatar for Tcll
0
302
Member Avatar for Gribouillis

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.

Member Avatar for Reverend Jim
0
239
Member Avatar for Raisefamous

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.

Member Avatar for Gribouillis
0
839
Member Avatar for wudie47

Hi. Here is a small experiment in the python console >>> "python.exe".rsplit('.', 1) ['python', 'exe'] It should be easy now !

Member Avatar for wudie47
0
507
Member Avatar for Slavi

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.

Member Avatar for Gribouillis
0
195
Member Avatar for Dani
Member Avatar for AutoPython
Member Avatar for Saran_1

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 …

Member Avatar for Saran_1
0
18K
Member Avatar for nk.shilpa

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 …

Member Avatar for nk.shilpa
0
257
Member Avatar for jamesjohnson25

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:]

Member Avatar for woooee
0
395
Member Avatar for happygeek

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.

Member Avatar for Tcll
1
519
Member Avatar for nsm2015

It looks like homework. Did you try to add the polynomials in a python console ?

Member Avatar for vegaseat
-1
161
Member Avatar for cereal
Member Avatar for Irene26

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 …

Member Avatar for Gribouillis
0
378
Member Avatar for hefaz
Member Avatar for Paven123

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 …

Member Avatar for vegaseat
0
344
Member Avatar for jamesjohnson25

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 …

Member Avatar for snippsat
0
301
Member Avatar for 승환

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 > …

Member Avatar for Gribouillis
0
480
Member Avatar for kouty

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. …

Member Avatar for kouty
0
947
Member Avatar for mark103

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') …

Member Avatar for Gribouillis
0
262
Member Avatar for Tcll

> 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 ?

Member Avatar for Gribouillis
0
549
Member Avatar for sludgecornell

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 …

Member Avatar for Gribouillis
0
174
Member Avatar for Tcll

> 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 …

Member Avatar for Tcll
0
208
Member Avatar for Manuela_1

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 ?

Member Avatar for Gribouillis
0
348
Member Avatar for greenleafone7

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.

Member Avatar for greenleafone7
0
179
Member Avatar for Niloofar24

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.

Member Avatar for Swati1486
0
367
Member Avatar for Felipe_1

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 …

Member Avatar for Gribouillis
0
221
Member Avatar for mark103

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 …

Member Avatar for Gribouillis
0
336
Member Avatar for venk7

Replace `+''+` with `,`. Why didn't you use `next(iter(...))` as I told you ?

Member Avatar for venk7
0
309
Member Avatar for seeit360

There is no fundamental difference between 5 years or 5 seconds from a computer's point of vue.

Member Avatar for <M/>
0
374
Member Avatar for davidbr

> 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 …

Member Avatar for Gribouillis
0
479
Member Avatar for Deebash_1

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.

Member Avatar for Gribouillis
0
260
Member Avatar for venk7

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 …

Member Avatar for Gribouillis
0
406
Member Avatar for lewashby

`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).

Member Avatar for vegaseat
0
2K
Member Avatar for Niloofar24

`touch foo` creates file `foo`, if that's what you mean, but I probably missed something in your question. (?)

Member Avatar for Niloofar24
0
266
Member Avatar for venk7

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 …

Member Avatar for Gribouillis
0
403
Member Avatar for vegaseat
Member Avatar for vegaseat
2
8K
Member Avatar for winecoding

> 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.

Member Avatar for vegaseat
0
400
Member Avatar for kouty

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 …

Member Avatar for kouty
0
305
Member Avatar for Tcll

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 …

Member Avatar for Tcll
0
1K
Member Avatar for cheeseman125

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.

Member Avatar for BustACode
0
246
Member Avatar for Tcll

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 …

Member Avatar for Tcll
0
260
Member Avatar for jolio5
Member Avatar for vegaseat
0
180
Member Avatar for Tcll

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 …

Member Avatar for Tcll
0
233
Member Avatar for K. Chris

It is a rather unusual first post. How could anybody have abused you as you joined 30 minutes ago ?

Member Avatar for Reverend Jim
-1
629
Member Avatar for tony75

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'

Member Avatar for EMERSON_1
0
10K
Member Avatar for Seher_1

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.

Member Avatar for Gribouillis
0
167
Member Avatar for python1

[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, …

Member Avatar for Parikshit_1
0
44K
Member Avatar for jamesjohnson25

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 …

Member Avatar for rubberman
0
267

The End.