GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing mail.python.org — Mailman 3 April 2024 - Python-list - python.org Python-list
Threads by month
April 2024
Hi everyone,
one thing that I do not understand is happening to me: I have some text
files with different characteristics, among these there are that they
have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them
without BOM. With those utf_32_xx I have no problem but with the
UTF_16_xx I have. If I have an utf_16_le coded file and I read it with
encoding='utf_16_le' I have no problem I read it, with
encoding='utf_16_be' I can read it without any error even if the data I
receive have the inverted bytes. The same thing happens with the
utf_16_be codified file, I read it, both with encoding='utf_16_be' and
with 'utf_16_le' without errors but in the last case the bytes are
inverted. What did I not understand? What am I doing wrong?
thanks in advance
Stefan Ram ha scritto:
> jak <nospam(a)please.ty> wrote or quoted:
>> I read it, both with encoding='utf_16_be' and
>> with 'utf_16_le' without errors but in the last case the bytes are
>> inverted.
>
> I think the order of the octets (bytes) is exactly the difference
> between these two encodings, so your observation isn't really
> surprising. The computer can't report an error here since it
> can't infer the correct encoding from the file data. It's like
> that koan: "A bit has the value 1. What does that mean?".
>
Understood. They are just 2 bytes and there is no difference between
them.
Thank you.
I am building a python work environment where
- i build python from sources
- install pip with the wheel bundled with python
- then install things with pip, like Jupyter
That environment is then deployed on various machines, at various
installation folders.
One issue I encounter, is the path to python in scripts like pip,
ipython, jupyter, etc is the original path where python is installed.
On linux, i can just do some sed in the problematic scripts.
On windows however, those scripts are python embedded in an EXE.
Probably generated by the same tool, as they all have a similar size
and a structure of an exe that contains a compressed __main__.py that
launch the relevant python module for the command.
What is the tool that creates those executables, and is there a way to
regenerate them from the python that has been deployed somewhere else,
so they point to the correct final path to python on that machine?
Since pip is able to create ipython.exe with path to my python
embedded for example, i assume i already have all i need in my python
installation to regenerate them?
/This announcement is in German since it targets a local user
group//meeting in Düsseldorf, Germany/
Ankündigung
Python Meeting Düsseldorf - April 2024
<https://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2024-04-17>
Ein Treffen von Python Enthusiasten und Interessierten
in ungezwungener Atmosphäre.
*17.04.2024, 18:00 Uhr*
Raum 1, 2.OG im Bürgerhaus Stadtteilzentrum Bilk
<http://www.duesseldorf.de/jugendamt/fam/famfoe/bueh/ac/index.shtml>
Düsseldorfer Arcaden
<http://www.duesseldorf-arcaden.de/anfahrt.html>, Bachstr. 145,
40217 Düsseldorf
<http://maps.google.com/maps?q=51.209169,6.775339&layer=c&sll=51.209353,6.77…>
Programm
Bereits angemeldete Vorträge:
* Marc-André Lemburg:
/*Advanced parsing structured data* with Python's new match statement
/
* Jens Diemer:
/Anbindung von *Tinkerforge* in Home Assistant
/
* Charlie Clark:
/Eine kleine *Datenanalyse
*/
* Detlef Lannert:
/Überblick über *CLI-Frameworks*/
Weitere Vorträge können gerne noch angemeldet werden. Bei Interesse,
bitte unter info(a)pyddf.de melden.
Startzeit und Ort
Wir treffen uns um 18:00 Uhr im Bürgerhaus in den Düsseldorfer Arcaden.
Das Bürgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet
sich an der Seite der Tiefgarageneinfahrt der Düsseldorfer Arcaden.
Über dem Eingang steht ein großes "Schwimm’ in Bilk" Logo. Hinter der
Tür direkt links zu den zwei Aufzügen, dann in den 2. Stock hochfahren.
Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt.
>>> Eingang in Google Street View <http://bit.ly/11sCfiw>
*⚠️ Wichtig*: Bitte nur dann anmelden, wenn ihr absolut sicher seid,
dass ihr auch kommt. Angesichts der begrenzten Anzahl Plätze, haben wir
kein Verständnis für kurzfristige Absagen oder No-Shows.
Einleitung
Das Python Meeting Düsseldorf <http://pyddf.de/> ist eine regelmäßige
Veranstaltung in Düsseldorf, die sich an Python Begeisterte aus der
Region wendet.
Einen guten Überblick über die Vorträge bietet unser PyDDF YouTube-Kanal
<http://www.youtube.com/pyddf/>, auf dem wir Videos der Vorträge nach
den Meetings veröffentlichen.
Veranstaltet wird das Meeting von der eGenix.com GmbH
<https://www.egenix.com/>, Langenfeld, in Zusammenarbeit mit Clark
Consulting & Research <http://www.clark-consulting.eu/>, Düsseldorf:
Format
Das Python Meeting Düsseldorf <http://pyddf.de/> nutzt eine Mischung aus
(Lightning) Talks und offener Diskussion.
Vorträge können vorher angemeldet werden, oder auch spontan während des
Treffens eingebracht werden. Ein Beamer mit HDMI und FullHD Auflösung
steht zur Verfügung.
(Lightning) Talk Anmeldung bitte formlos per EMail an info(a)pyddf.de
<mailto:[email protected]?subject=Anmeldung Lightning Talk Python Meeting Düsseldorf>
Kostenbeteiligung
Das Python Meeting Düsseldorf <http://pyddf.de/> wird von Python Nutzern
für Python Nutzer veranstaltet.
Da Tagungsraum, Beamer, Internet und Getränke Kosten produzieren, bitten
wir die Teilnehmer um einen Beitrag in Höhe von EUR 10,00 inkl. 19%
Mwst. Schüler und Studenten zahlen EUR 5,00 inkl. 19% Mwst.
Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen.
Anmeldung
Da wir nur 25 Personen in dem angemieteten Raum empfangen können,
möchten wir bitten, sich vorher anzumelden.
*Meeting Anmeldung* bitte per Meetup
<https://www.meetup.com/Python-Meeting-Dusseldorf/>
Weitere Informationen
Weitere Informationen finden Sie auf der Webseite des Meetings:
https://pyddf.de/
Viel Spaß !
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Experts (#1, Apr 15 2024)
>>> Python Projects, Coaching and Support ... https://www.egenix.com/
>>> Python Product Development ... https://consulting.egenix.com/
________________________________________________________________________
::: We implement business ideas - efficiently in both time and costs :::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
https://www.egenix.com/company/contact/
https://www.malemburg.com/
Stefan Ram ha scritto:
> jak <nospam(a)please.ty> wrote or quoted:
>> Stefan Ram ha scritto:
>>> df = df.where( df == 'zz' ).stack().reset_index()
>>> result ={ 'zz': list( zip( df.iloc[ :, 0 ], df.iloc[ :, 1 ]))}
>> Since I don't know Pandas, I will need a month at least to understand
>> these 2 lines of code. Thanks again.
>
> Here's a technique to better understand such code:
>
> Transform it into a program with small statements and small
> expressions with no more than one call per statement if possible.
> (After each litte change check that the output stays the same.)
>
> import pandas as pd
>
> # Warning! Will overwrite the file 'file_20240412201813_tmp_DML.csv'!
> with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out:
> print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6
> foo1,aa,ab,zz,ad,ae,af
> foo2,ba,bb,bc,bd,zz,bf
> foo3,ca,zz,cc,cd,ce,zz
> foo4,da,db,dc,dd,de,df
> foo5,ea,eb,ec,zz,ee,ef
> foo6,fa,fb,fc,fd,fe,ff''', file=out )
> # Note the "index_col=0" below, which is important here!
> df = pd.read_csv( 'file_20240412201813_tmp_DML.csv', index_col=0 )
>
> selection = df.where( df == 'zz' )
> selection_stack = selection.stack()
> df = selection_stack.reset_index()
> df0 = df.iloc[ :, 0 ]
> df1 = df.iloc[ :, 1 ]
> z = zip( df0, df1 )
> l = list( z )
> result ={ 'zz': l }
> print( result )
>
> I suggest to next insert print statements to print each intermediate
> value:
>
> # Note the "index_col=0" below, which is important here!
> df = pd.read_csv( 'file_20240412201813_tmp_DML.csv', index_col=0 )
> print( 'df = \n', type( df ), ':\n"', df, '"\n' )
>
> selection = df.where( df == 'zz' )
> print( "result of where( df == 'zz' ) = \n", type( selection ), ':\n"',
> selection, '"\n' )
>
> selection_stack = selection.stack()
> print( 'result of stack() = \n', type( selection_stack ), ':\n"',
> selection_stack, '"\n' )
>
> df = selection_stack.reset_index()
> print( 'result of reset_index() = \n', type( df ), ':\n"', df, '"\n' )
>
> df0 = df.iloc[ :, 0 ]
> print( 'value of .iloc[ :, 0 ]= \n', type( df0 ), ':\n"', df0, '"\n' )
>
> df1 = df.iloc[ :, 1 ]
> print( 'value of .iloc[ :, 1 ] = \n', type( df1 ), ':\n"', df1, '"\n' )
>
> z = zip( df0, df1 )
> print( 'result of zip( df0, df1 )= \n', type( z ), ':\n"', z, '"\n' )
>
> l = list( z )
> print( 'result of list( z )= \n', type( l ), ':\n"', l, '"\n' )
>
> result ={ 'zz': l }
> print( "value of { 'zz': l }= \n", type( result ), ':\n"',
> result, '"\n' )
>
> print( result )
>
> Now you can see what each single step does!
>
> df =
> <class 'pandas.core.frame.DataFrame'> :
> " foo1 foo2 foo3 foo4 foo5 foo6
> obj
> foo1 aa ab zz ad ae af
> foo2 ba bb bc bd zz bf
> foo3 ca zz cc cd ce zz
> foo4 da db dc dd de df
> foo5 ea eb ec zz ee ef
> foo6 fa fb fc fd fe ff "
>
> result of where( df == 'zz' ) =
> <class 'pandas.core.frame.DataFrame'> :
> " foo1 foo2 foo3 foo4 foo5 foo6
> obj
> foo1 NaN NaN zz NaN NaN NaN
> foo2 NaN NaN NaN NaN zz NaN
> foo3 NaN zz NaN NaN NaN zz
> foo4 NaN NaN NaN NaN NaN NaN
> foo5 NaN NaN NaN zz NaN NaN
> foo6 NaN NaN NaN NaN NaN NaN "
>
> result of stack() =
> <class 'pandas.core.series.Series'> :
> " obj
> foo1 foo3 zz
> foo2 foo5 zz
> foo3 foo2 zz
> foo6 zz
> foo5 foo4 zz
> dtype: object "
>
> result of reset_index() =
> <class 'pandas.core.frame.DataFrame'> :
> " obj level_1 0
> 0 foo1 foo3 zz
> 1 foo2 foo5 zz
> 2 foo3 foo2 zz
> 3 foo3 foo6 zz
> 4 foo5 foo4 zz "
>
> value of .iloc[ :, 0 ]=
> <class 'pandas.core.series.Series'> :
> " 0 foo1
> 1 foo2
> 2 foo3
> 3 foo3
> 4 foo5
> Name: obj, dtype: object "
>
> value of .iloc[ :, 1 ] =
> <class 'pandas.core.series.Series'> :
> " 0 foo3
> 1 foo5
> 2 foo2
> 3 foo6
> 4 foo4
> Name: level_1, dtype: object "
>
> result of zip( df0, df1 )=
> <class 'zip'> :
> " <zip object at 0x000000000B3B9548>"
>
> result of list( z )=
> <class 'list'> :
> " [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), ('foo5', 'foo4')]"
>
> value of { 'zz': l }=
> <class 'dict'> :
> " {'zz': [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), ('foo5', 'foo4')]}"
>
> {'zz': [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), ('foo5', 'foo4')]}
>
> The script reads a CSV file and stores the data in a Pandas
> DataFrame object named "df". The "index_col=0" parameter tells
> Pandas to use the first column as the index for the DataFrame,
> which is kinda like column headers.
>
> The "where" creates a new DataFrame selection that contains
> the same data as df, but with all values replaced by NaN (Not
> a Number) except for the values that are equal to 'zz'.
>
> "stack" returns a Series with a multi-level index created
> by pivoting the columns. Here it gives a Series with the
> row-col-addresses of a all the non-NaN values. The general
> meaning of "stack" might be the most complex operation of
> this script. It's explained in the pandas manual (see there).
>
> "reset_index" then just transforms this Series back into a
> DataFrame, and ".iloc[ :, 0 ]" and ".iloc[ :, 1 ]" are the
> first and second column, respectively, of that DataFrame. These
> then are zipped to get the desired form as a list of pairs.
>
And this is a technique very similar to reverse engineering. Thanks for
the explanation and examples. All this is really clear and I was able to
follow it easily because I have already written a version of this code
in C without any kind of external library that uses the .CSV version of
the table as data ( 234 code lines :^/ ).
Hi folks!
I'd like to split my package tree into several IDE projects and build a
custom
importer to import
'top.child1.child2'
from the directory
<python-path-entry>/top.child1.child2/__init__.py
so basically replacing the dots with slashes and having the package content
lying directly in the project folder. I have come up with this:
=== usercustomize.py ===
1 import sys
2 from importlib.machinery import ModuleSpec
3 from pathlib import Path
4
5 Loader = type(__spec__.loader)
6
7 class IdeHelper:
8 @classmethod
9 def find_spec(cls, name, path, target=None):
10 for dirname in sys.path:
11 dirobj = Path(dirname)
12 if dirobj.name == name:
13 break
14 else:
15 return None
16 origin = str(dirobj.joinpath('__init__.py').absolute())
17 ret = ModuleSpec(name, Loader(name, origin), origin=origin)
18 return ret
19
20 sys.meta_path.append(IdeHelper)
which I'm on the right direction with. Unfortunately, I'm getting errors
while
importing a subpackage. With 'import top.child1' the error is
ModuleNotFoundError: No module named 'top.child1'; 'top' is not a
package
whereas with 'from top import child1' the error changes to
ImportError: cannot import name 'child1' from 'top' (unknown location)
How can I make this work?
Best wishes,
Fabiano
Stefan Ram ha scritto:
> jak <nospam(a)please.ty> wrote or quoted:
>> Would you show me the path, please?
>
> I was not able to read xls here, so I used csv instead; Warning:
> the script will overwrite file "file_20240412201813_tmp_DML.csv"!
>
> import pandas as pd
>
> with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out:
> print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6
> foo1,aa,ab,zz,ad,ae,af
> foo2,ba,bb,bc,bd,zz,bf
> foo3,ca,zz,cc,cd,ce,zz
> foo4,da,db,dc,dd,de,df
> foo5,ea,eb,ec,zz,ee,ef
> foo6,fa,fb,fc,fd,fe,ff''', file=out )
>
> df = pd.read_csv( 'file_20240412201813_tmp_DML.csv' )
>
> result = {}
>
> for rownum, row in df.iterrows():
> iterator = row.items()
> _, rowname = next( iterator )
> for colname, value in iterator:
> if value not in result: result[ value ]= []
> result[ value ].append( ( rowname, colname ))
>
> print( result )
>
In reality what I wanted to achieve was this:
what = 'zz'
result = {what: []}
for rownum, row in df.iterrows():
iterator = row.items()
_, rowname = next(iterator)
for colname, value in iterator:
if value == what:
result[what] += [(rowname, colname)]
print(result)
In any case, thank you again for pointing me in the right direction. I
had lost myself looking for a pandas method that would do this in a
single shot or almost.
Hello List,
I have a simple question. I use the following textPrompt in some of my Jython modules:
'\n[1;33mYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True)
Is there a way to add an ANSI color code to the end where the conditions are, so that the color of the user’s input is of a color of my choosing, instead of just white?
Thank you very much in advance.
Kind regards,
Bill Kochman
Hi everyone.
I state that I don't know anything about 'pandas' but I intuited that
it could do what I want. I get, through the "read_excel" method, a
table similar to this:
obj| foo1 foo2 foo3 foo4 foo5 foo6
-----------------------------------
foo1| aa ab zz ad ae af
|
foo2| ba bb bc bd zz bf
|
foo3| ca zz cc cd ce zz
|
foo4| da db dc dd de df
|
foo5| ea eb ec zz ee ef
|
foo6| fa fb fc fd fe ff
And I would like to get a result similar to this:
{
'zz':[('foo1','foo3'),
('foo2','foo5'),
('foo3','foo2'),
('foo3','foo6'),
('foo5','foo4')
]
}
Would you show me the path, please?
Thank you in advance.
|
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |