Doc or example about conda custom build?
Sorry for being maybe a little OT. I tried to get help from other Conda users, from chat and from the mailing list without success. I would add a custom build on my conda package. Is there somewhere a doc or an example about it? (Specifically, I want to pass a custom parameter to the setup.py that lets me package only the pure py version of the code.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Why operations between dict views return a set and not a frozenset?
Thank you a lot for letting me understand :) On Tue, 11 Jan 2022 at 22:09, Peter J. Holzer wrote: > On 2022-01-11 19:49:20 +0100, Marco Sulla wrote: > > I think this is what you mean: > > > > >>> dis.dis("for _ in {1, 2}: pass") > > 1 0 SETUP_LOOP 12 (to 14) > > 2 LOAD_CONST 3 (frozenset({1, 2})) > > 4 GET_ITER > > >>6 FOR_ITER 4 (to 12) > > 8 STORE_NAME 0 (_) > > 10 JUMP_ABSOLUTE6 > > >> 12 POP_BLOCK > > >> 14 LOAD_CONST 2 (None) > > 16 RETURN_VALUE > > >>> a = {1, 2} > > >>> dis.dis("for _ in a: pass") > > 1 0 SETUP_LOOP 12 (to 14) > > 2 LOAD_NAME0 (a) > > 4 GET_ITER > > >>6 FOR_ITER 4 (to 12) > > 8 STORE_NAME 1 (_) > > 10 JUMP_ABSOLUTE6 > > >> 12 POP_BLOCK > > >> 14 LOAD_CONST 0 (None) > > 16 RETURN_VALUE > > I think you have omitted the part that Chris was hinting at. > > >>> dis.dis("a = {1, 2};\nfor _ in a: pass") > 1 0 LOAD_CONST 0 (1) > 2 LOAD_CONST 1 (2) > 4 BUILD_SET2 > 6 STORE_NAME 0 (a) > > 2 8 LOAD_NAME0 (a) > 10 GET_ITER > >> 12 FOR_ITER 4 (to 18) > 14 STORE_NAME 1 (_) > 16 JUMP_ABSOLUTE 12 > >> 18 LOAD_CONST 2 (None) > 20 RETURN_VALUE > > Now compare > > 2 LOAD_CONST 3 (frozenset({1, 2})) > > with > > 1 0 LOAD_CONST 0 (1) > 2 LOAD_CONST 1 (2) > 4 BUILD_SET2 > > and you see the difference between using a frozenset as a constant and > building a set at runtime. > > hp > > -- >_ | Peter J. Holzer| Story must make more sense than reality. > |_|_) || > | | | h...@hjp.at |-- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!" > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Writing a string with comma in one column of CSV file
On 1/15/22 13:56, Mahmood Naderan via Python-list wrote: > Hi, > I use the following line to write some information to a CSV file which is > comma delimited. > > f = open(output_file, 'w', newline='') > wr = csv.writer(f) > ... > f.write(str(n) + "," + str(key) + "\n" ) > > > Problem is that key is a string which may contain ',' and this causes the > final CSV file to have more than 2 columns, while I want to write the whole > key as a single column. One of the reasons csv is a horrible data interchange format. If you must... the convention for Excel, which is usually the reason people are using csv, is you can enclose the entire comma-containing field in "quote marks" (afaik it must be double-quote). The convention for other consumers of csv may or may not accept this - if it's not for Excel you'll need to check. One gotcha - the opening quote must appear immediately after the preceding comma separator, you can't pad with spaces. That is: "this","should","be","okay, I think" and not: "this", "will", "not", "work", "correctly, I fear" (the single-word row entries don't have to be in quotes, of course) If you use the Python csv module it should take care of this - you can specify the separator sequence and the quote sequence, and it knows to quote a field correctly if it contains the separator. Highly recommended. -- https://mail.python.org/mailman/listinfo/python-list
Re: What to write or search on github to get the code for what is written below:
On 1/15/22 14:24, Avi Gross via Python-list wrote: > Mats, > Yes, this is a Python mailing list and I welcome people interested in doing > something in Python who need a little help or advice but have some idea of > what they are doing and present us with enough info more than "something does > not work." > > Yes, the topic was raised on a Python list but I did not get the impression > the person asking necessarily knew a lot about Python or maybe other > languages. I may well be wrong. They seem to have been handed something to > work on and maybe are searching for some way to do it. You can do what was > asked in plenty of languages, some easier and some harder. But some are > better set to do things in a browser/server model than others. I only meant, in response to "someone suggested" in the quoted snip below, since it was asked here, someone suggesting Python was a pretty expected outcome... > -Original Message- > From: Mats Wichmann > To: python-list@python.org > Sent: Sat, Jan 15, 2022 3:05 pm > Subject: Re: What to write or search on github to get the code for what is > written below: > > On 1/13/22 16:08, Avi Gross via Python-list wrote: >> >> I am not replying to anything below so I have removed it. > >> Instead, someone suggested Python which indeed, with lots of work, can open >> just about ANY nonsensical file and diddle around and rewrite it, but WHY? > > well, the topic *was* raised on a PYTHON list... > > -- https://mail.python.org/mailman/listinfo/python-list
Re: What to write or search on github to get the code for what is written below:
On Sat, 15 Jan 2022 02:38:34 -0800 (PST), NArshad declaimed the following: A bit of an improvement -- actual code... But... still not a minimal /runnable/ example... > >Why does the code written below is not giving any output? > >xls = ExcelFile('ABC.xlsx') Where is "ExcelFile" defined? Best match I could find after spending time with Google is the pandas package. Pandas is likely overkill for this situation -- being optimized for analysis of numerical tabular data. In particular, it expects each column to be of one data type, not mixed data types, in order to apply aggregate functions (min, max, mean, std.dev., etc.) to the columns. >df = xls.parse(xls.sheet_names[0], index_col=1) Based upon documentation, pandas.ExcelFile.parse() internally uses the openpyxl package for files of type .xlsx -- for this application openpyxl is probably all that is needed. Documentation for .parse() (actually the underlying .read_excel() operation) indicates that the desired sheet can be specified by name OR BY POSITION -- with the default value being "0" [first sheet]. It is somewhat perverse to be retrieving a list sheet names from the file, only to then pass the first name back into the function which has to match the name up against the list to determine the position... Unless the file is using multiple sheets for data -- in which case you need some logic to select something other than the first sheet -- you could leave that argument off and let it default. index_col=1 says to use the SECOND COLUMN of the sheet to provide row-labels for the "dataframe" (unless documentation states otherwise, the first item of a collection is "0", not "1") >x=df.to_dict() What do you really expect from this conversion? With no arguments it will produce a nested dictionary of the form { "column1name" : { "row1name" : r1-c1-value , "row2name" : r2-c1-value}, "column2name" : { "row1name" : r1-c2-value, "row2name" : r2-c2-value} } >print (x) > >Only the contents of the first column and the column number is required in the >dictionary You won't get that with .to_dict() -- it uses the column names for the major grouping, and then uses the row names (which are already garbage as you told pandas to use the second column for row names) to select the VALUE stored in that row for that column. Also, while Python implementation of dictionaries has changed over the years, the theoretical basis (associative mapping, hash table) does not define an order for the keys of the dictionary. Unless you are certain of how a dictionary handles insert/delete of keys, you can not assume the first key out was the first key that went in. It would also be helpful to have a snippet of the spreadsheet -- say the first five or six rows, along with the first five or six columns; exported as a CSV file (binary attachments get stripped from this forum, but a CSV is text and can be pasted in -- 5x5 should be small enough that those trying to assist can then extract it from the post, clean up any line wrappings, and import into a blank spreadsheet. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Writing a string with comma in one column of CSV file
On 17/01/22 4:18 am, Mats Wichmann wrote: the convention for Excel, which is usually the reason people are using csv, is you can enclose the entire comma-containing field in "quote marks" (afaik it must be double-quote). And to include a double quote in a field, quote the field and double the double-quote. Another quirk is that Excel allows newlines in a quoted field, which causes problems for naive parsers that split the input into lines first and then analyse it into fields. (A particular non-Python one I use professionally is guilty of this...) -- Greg -- https://mail.python.org/mailman/listinfo/python-list