-
Replied To a Post in Restart your python program.
> This just restarts the shell are you using idle ? another ide ? -
Replied To a Post in how to calculate a common exponent from a bunch of float values??
> where's your common exponent to evaluate all those "ints" (the n.0 floats) by?? Well my idea is to take the smallest exponent which yields an int for each of … -
Replied To a Post in how to calculate a common exponent from a bunch of float values??
Here is another way, using the machine representation of floating numbers #!/usr/bin/env python # -*-coding: utf8-*- '''computes power 2 valuation in machine floats ''' from __future__ import (absolute_import, division, print_function, … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
The code will not define the rules. It works the other way: you define precise rules, then they can be implemented in code. Otherwise the program will work for this … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
The question is why MonthDayCount1, MonthDayCount2 etc and not Int321, Int322, etc. By which rule do the Int32 vanish ? -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
In the xml file, there is no datetime1 datetime2 datetime3. The 1 2 3 etc must be added somewhere. That's what I meant when I said earlier that I dont … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Because you changed my functions `flatten_dict()` and `flatten_list()`. Take the versions I wrote above. -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Instead of calling `flatten_dict(root)`, you would call `pairs_from_root(root)`. You need to do this only once at the bottom of the program. This will change the CSV structure in the sense … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
The question is what do you want to have instead of `'Response.MemberO.PMembers.PMembers.Member.CurrentEmployer.EmployerAddress.TimeAtPreviousAddress'` ? If you want to have only `'TimeAtPreviousAddress'` you can obtain this without changing the generator, but instead … -
Replied To a Post in how to calculate a common exponent from a bunch of float values??
I dont understand you examples. If you think the anyfloat rounding will screw up the result, you can keep the same exponent, I mean shorten only the mantissa from anyfloat … -
Replied To a Post in how to calculate a common exponent from a bunch of float values??
> 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, … -
Replied To a Post in Wrong Last updated link
I tried with qupzilla, firefox, opera, rekonq and konqueror. All the browsers show the last post as coming from Raisefamous. Are you sure you visited the [python forum page](https://www.daniweb.com/software-development/python/114) ? … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
This works very well for me: first a file parsexml2.py # parsexml2.py import xml.etree.cElementTree as ElementTree import csv def flatten_list(aList, prefix=''): for element in aList: if element: # treat like … -
Created Wrong Last updated link
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 … -
Replied To a Post in Python program crashes after using too much memory
Did you try to run `coinTest()` in a subprocess ? -
Tweeted Email Alerts Not Working
I can't figure out why but at the minute I have no instant emails about thread updates etc. Have I got any settings wrong or is something else amiss under … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Why not updating the code by yourself ? Here is the solution def makerows(pairs): headers = [] columns = {} for k, v in pairs: if k in columns: columns[k].extend((v,)) … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Great ! Then mark the thread as solved ! -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Try what you can. It should be easy to write the csv. -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
This should work def makerows(pairs): headers = [] columns = {} for k, v in pairs: if k in columns: columns[k].extend(('', k, v)) else: headers.append(k) columns[k] = [k, v] m … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
And if we have L = [('A', 1), ('B', 2), ('C', 3), ('D', 4),('A', 5), ('B', 6), ('D', 8)] you want A B C D 1 2 3 4 A … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
So you mean the headers A B C D, then a first row of values 1 2 3 4, then a blank row, then a row A B C D again and … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Do you mean that you now want 2 csv files ? -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
I don't understand your problem. If you have the list L = [('A', 1), ('B', 2), ('C', 3), ('D', 4),('A', 5), ('B', 6), ('C', 7), ('D', 8)] and you want … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
The `flatten_dict()` function returns an iterable sequence of `(key, value)` pairs. You can turn this to a list of pairs with `list(flatten_dict(root))`. A list of pairs L (or a iterable … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
You don't understand the output of flatten_dict(). You can do this def main(): with open('source.xml', 'r', encoding='utf-8') as f: xml_string = f.read() xml_string= xml_string.replace('�', '') #optional to remove ampersands. root … -
Replied To a Post in Write a function need help.
No, `fileList` is `['python.exe','java.exe','myassign.py','mydoc.doc']` and `fileExtension` is `'doc'`. -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
If there is still a dot at the end of a column header, it would be better to remove it (`'Response.R.'` becomes `'Response.R'`). For this, use the `rstrip('.')` method. By … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
The problem is that I dont understand your rule for key generation. If you want to keep only the last word, it is very easy to do for key, value … -
Replied To a Post in Write a function need help.
It looks easy if you write pseudo-code def fileExtensionExists(fileList, fileExtension): for fileName in fileList: get this filename''s extension, call this 'extension' (use parseExtension) if extension == fileExtension: return True # … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Here is a variant which handles lists differently by enumerating the list items and removing their common tag. It works for MonthDayCount in your example, but I'm not sure it … -
Replied To a Post in Python program crashes after using too much memory
It is very strange that the program crashes the PC. Did you discover a bug in one of the imported modules ? One thing I would try if I were … -
Replied To a Post in Python program crashes after using too much memory
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 … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
I transformed the activestate recipe into a generator which flattens the xml structure. Look at the ouput, then try to define how you would transform the keys to get correct … -
Replied To a Post in Write a function need help.
> Using user input could be anything That's why you have a variable or function parameter named `filename`. You must use this variable instead of `"python.exe"`. -
Replied To a Post in Fake end of file ...
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. -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
I see that you are using an old [activestate recipe](http://code.activestate.com/recipes/410469-xml-as-dictionary/) to parse xml and transform it into a dictionary. It means that the comments in this code don't have anything … -
Replied To a Post in Write a function need help.
Hi. Here is a small experiment in the python console >>> "python.exe".rsplit('.', 1) ['python', 'exe'] It should be easy now ! -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Yes put the snippet in a file named `postprocess.py` then write from postprocess import post_process -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Here is an example of what you can do. This function transforms a dictionary by *exploding* the inner lists if they contain only strings from postprocess import post_process @post_process(dict) def … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Here is a simple transformation snippet >>> key = 'spam' >>> L = ['foo', 'bar', 'baz'] >>> [('{}{}'.format(key, i), value) for i, value in enumerate(L, 1)] [('spam1', 'foo'), ('spam2', 'bar'), … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
> the key is replicated n number of times for n number of items in its associated list Every output is possible, only the rules which govern the production of … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
> Interestingly, with your function on other files I get the following error I made the assumption that if the json file contains arrays with more than one item, all … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Here is the kind of code that you can try import csv import json import sys def shrink(v): while True: if isinstance(v, list): if len(v) == 1: v = v[0] … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
If you want to adapt the flatten function to the case where the json code contains arrays, you must first describe which key/value pairs you expect as output from the … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
Ok, it looks easy. The ValueError is thrown by the json parser (function `json.load()`) because your json file is an invalid json file. It contains a pair key/value outside of … -
Replied To a Post in Python learners doubt
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 … -
Replied To a Post in AttributeError: 'str' object has no attribute 'keys'
Of course you must do a bit of parsing, for example here is how to generate the pairs in the above example (the code must be modified if the json … -
Replied To a Post in Reassigning keys in dictionary of lists and then writing out to CSV file?
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 ...). … -
Replied To a Post in AttributeError: 'str' object has no attribute 'keys'
Well, here is a basic exemple of incremental json parsing with the ijson module. I added a subobject foo inside Fee in your json file. #!/usr/bin/env python3 # -*-coding: utf8-*- …
The End.