OT: Is there a name for this transformation?

2019-07-10 Thread kamaraju kusumanchi
Given a csv file with the following contents

20180701, A
20180702, A, B
20180703, A, B, C
20180704, B, C
20180705, C

I would like to transform the underlying data into a dataframe such as

date, A, B, C
20180701,  True, False, False
20180702,  True,  True, False
20180703,  True,  True,  True
20180704, False,  True,  True
20180705, False, False,  True

the idea is that the first field in each line of the csv is the row
index of the dataframe. The subsequent fields will be its column names
and the values in the dataframe tell whether that element is present
or not in the line.

Is there a name for this transformation? Any existing code/library
that can transform data back and forth between the two formats? I can
write one myself if there is none but trying to avoid reinventing the
wheel if possible.

thanks in advance
raju
-- 
Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difficulties configuring LTO on macOS with clang

2019-07-10 Thread Scott Colby
Unfortunately that path is absent on my system. Could the issue be that the 
llvm version of ar is not present at all on macOS? What remains confusing in 
that case is that by using CC=cc (and I assume just ar) the LTO compilation 
succeeds, despite cc being a symlink to clang anyway.

Thanks,
Scott

On Tue, Jul 9, 2019, at 15:39, Barry Scott wrote:
> 
> 
> > On 9 Jul 2019, at 19:28, Scott Colby  wrote:
> > 
> > Hello all,
> > 
> > I am having difficulty building Python with `--with-lto` on macOS 10.14.5. 
> > With a clean checkout of the CPython source at the tagged release for 
> > 3.7.4, I ran:
> > 
> > $ ./configure --prefix=/opt/python3.7.4 --enable-optimizations 
> > --enable-ipv6 --with-lto --with-openssl=$(brew --prefix openssl) CC=clang
> > checking for git... found
> > checking build system type... x86_64-apple-darwin18.6.0
> > checking host system type... x86_64-apple-darwin18.6.0
> > checking for python3.7... python3.7
> > checking for --enable-universalsdk... no
> > checking for --with-universal-archs... no
> > checking MACHDEP... checking for --without-gcc... no
> > checking for --with-icc... no
> > checking for gcc... clang
> > checking whether the C compiler works... yes
> > checking for C compiler default output file name... a.out
> > checking for suffix of executables...
> > checking whether we are cross compiling... no
> > checking for suffix of object files... o
> > checking whether we are using the GNU C compiler... yes
> > checking whether clang accepts -g... yes
> > checking for clang option to accept ISO C89... none needed
> > checking how to run the C preprocessor... clang -E
> > checking for grep that handles long lines and -e... /usr/bin/grep
> > checking for a sed that does not truncate output... /usr/bin/sed
> > checking for --with-cxx-main=... no
> > checking for clang++... no
> > configure:
> > 
> > By default, distutils will build C++ extension modules with "clang++".
> > If this is not intended, then set CXX on the configure command line.
> > 
> > checking for the platform triplet based on compiler characteristics... 
> > darwin
> > checking for -Wl,--no-as-needed... no
> > checking for egrep... /usr/bin/grep -E
> > checking for ANSI C header files... yes
> > checking for sys/types.h... yes
> > checking for sys/stat.h... yes
> > checking for stdlib.h... yes
> > checking for string.h... yes
> > checking for memory.h... yes
> > checking for strings.h... yes
> > checking for inttypes.h... yes
> > checking for stdint.h... yes
> > checking for unistd.h... yes
> > checking minix/config.h usability... no
> > checking minix/config.h presence... no
> > checking for minix/config.h... no
> > checking whether it is safe to define __EXTENSIONS__... yes
> > checking for the Android API level... not Android
> > checking for --with-suffix...
> > checking for case-insensitive build directory... yes
> > checking LIBRARY... libpython$(VERSION)$(ABIFLAGS).a
> > checking LINKCC... $(PURIFY) $(MAINCC)
> > checking for GNU ld... no
> > checking for --enable-shared... no
> > checking for --enable-profiling... no
> > checking LDLIBRARY... libpython$(VERSION)$(ABIFLAGS).a
> > checking for ar... ar
> > checking for readelf... no
> > checking for a BSD-compatible install... /usr/local/bin/ginstall -c
> > checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p
> > checking for --with-pydebug... no
> > checking for --with-assertions... no
> > checking for --enable-optimizations... yes
> > checking for --with-lto... yes
> > checking target system type... x86_64-apple-darwin18.6.0
> > checking for -llvm-ar... no
> > checking for llvm-ar... ''
> > configure: error: llvm-ar is required for a --with-lto build with clang but 
> > could not be found.
> 
> I see /opt/local/bin/llvm-ar-mp-4.0 which ends up running the llvm-ar from 
> /opt/local/libexec/llvm-4.0/bin
> 
> Just a guess but maybe you need to add /opt/local/libexec/llvm-4.0/bin/ to 
> your path
> as its where llvm-ar is.
> 
> Barry
> 
> > 
> > If I change the command to `... CC=cc` configuration appears to happen 
> > normally.
> > 
> > On my version of macOS, cc is a symlink to clang.
> > 
> > Why is this happening? What should I be doing differently to explicitly 
> > specify clang as my compiler?
> > 
> > Thank you,
> > Scott Colby
> > -- 
> > https://mail.python.org/mailman/listinfo/python-list
> > 
> 
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


issue

2019-07-10 Thread joshua kay
Hello,
i am encountering a issue with python 3.7.2rc1 64 bit currently
My operating system is windows 10 and every time i try to run my code the
shell just says:
== RESTART: C:\Users\joshu\OneDrive\Desktop\python\projects\multi choice.py
==

I how scanned the internet looking for a solution until i was made aware by
the python installer about the support team, please tell me a solution for
my issue

thank you,
Joshua kay
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue

2019-07-10 Thread Calvin Spealman
If you could share the code you are trying to run, which is causing the
issue, someone might be able to help. Without that, it is doubtful you'll
get any help.

On Wed, Jul 10, 2019 at 11:08 AM joshua kay  wrote:

> Hello,
> i am encountering a issue with python 3.7.2rc1 64 bit currently
> My operating system is windows 10 and every time i try to run my code the
> shell just says:
> == RESTART: C:\Users\joshu\OneDrive\Desktop\python\projects\multi choice.py
> ==
>
> I how scanned the internet looking for a solution until i was made aware by
> the python installer about the support team, please tell me a solution for
> my issue
>
> thank you,
> Joshua kay
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

CALVIN SPEALMAN

SENIOR QUALITY ENGINEER

[email protected]  M: +1.336.210.5107
[image: https://red.ht/sig] 
TRIED. TESTED. TRUSTED. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Pythonic custom multi-line parsers

2019-07-10 Thread Johannes Bauer
Hi list,

I'm looking for ideas as to a pretty, Pythonic solution for a specific
problem that I am solving over and over but where I'm never happy about
the solution in the end. It always works, but never is pretty. So see
this as an open-ended brainstorming question.

Here's the task: There's a custom file format. Each line can be parsed
individually and, given the current context, the meaning of each
individual line is always clearly distinguishable. I'll give an easy
example to demonstrate:


moo = koo
bar = foo
foo :=
   abc
   def
baz = abc

Let's say the root context knows only two regexes and give them names:

keyvalue: \w+ = \w+
start-multiblock: \w+ :=

The keyvalue is contained in itself, when the line is successfully
parsed all the information is present. The start-multiblock however
gives us only part of the puzzle, namely the name of the following
block. In the multiblock context, there's different regexes that can
happen (actually only one):

multiblock-item: \s\w+

Now obviously whe the block is finished, there's no delimiter. It's
implicit by the multiblock-item regex not matching and therefore we
backtrack to the previous parser (root parser) and can successfully
parse the last line baz = abc.

Especially consider that even though this is a simple example, generally
you'll have multiple contexts, many more regexes and especially nesting
inside these contexts.

Without having to use a parser generator (for those the examples I deal
with are usually too much overhead) what I usually end up doing is
building a state machine by hand. I.e., I memorize the context, match
those and upon no match manually delegate the input data to backtracked
matchers.

This results in AWFULLY ugly code. I'm wondering what your ideas are to
solve this neatly in a Pythonic fashion without having to rely on
third-party dependencies.

Cheers,
Joe
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue

2019-07-10 Thread Terry Reedy

On 7/10/2019 10:35 AM, joshua kay wrote:

Hello,
i am encountering a issue with python 3.7.2rc1 64 bit currently
My operating system is windows 10 and every time i try to run my code the
shell just says:
== RESTART: C:\Users\joshu\OneDrive\Desktop\python\projects\multi choice.py
==


You are running your code from an IDLE editor.  The above is what you 
*should* see when you hit F5 or Run => Run Module.  This is not a problem.


If the above is all you ever see, not even a '>>> ' prompt, then the 
almost certain problem is that your program runs 'forever' without 
producing output.  Examples: "while True: pass" will run the cpu at full 
speed, not good; "s = input()" will wait for input forever.  Try putting 
some print statements in your code to determine where it is stuck.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Pythonic custom multi-line parsers

2019-07-10 Thread Rob Gaddi

On 7/10/19 10:50 AM, Johannes Bauer wrote:

Hi list,

I'm looking for ideas as to a pretty, Pythonic solution for a specific
problem that I am solving over and over but where I'm never happy about
the solution in the end. It always works, but never is pretty. So see
this as an open-ended brainstorming question.

Here's the task: There's a custom file format. Each line can be parsed
individually and, given the current context, the meaning of each
individual line is always clearly distinguishable. I'll give an easy
example to demonstrate:


moo = koo
bar = foo
foo :=
abc
def
baz = abc

Let's say the root context knows only two regexes and give them names:

keyvalue: \w+ = \w+
start-multiblock: \w+ :=

The keyvalue is contained in itself, when the line is successfully
parsed all the information is present. The start-multiblock however
gives us only part of the puzzle, namely the name of the following
block. In the multiblock context, there's different regexes that can
happen (actually only one):

multiblock-item: \s\w+

Now obviously whe the block is finished, there's no delimiter. It's
implicit by the multiblock-item regex not matching and therefore we
backtrack to the previous parser (root parser) and can successfully
parse the last line baz = abc.

Especially consider that even though this is a simple example, generally
you'll have multiple contexts, many more regexes and especially nesting
inside these contexts.

Without having to use a parser generator (for those the examples I deal
with are usually too much overhead) what I usually end up doing is
building a state machine by hand. I.e., I memorize the context, match
those and upon no match manually delegate the input data to backtracked
matchers.

This results in AWFULLY ugly code. I'm wondering what your ideas are to
solve this neatly in a Pythonic fashion without having to rely on
third-party dependencies.

Cheers,
Joe



That's pretty much what I do.  I generally make the parser a class and each 
state a method.  Every line the parser takes out of the file it passes to 
self.statefn, which processes the line in the current context and updates 
self.statefn to a different method if necessary.


--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Re: OT: Is there a name for this transformation?

2019-07-10 Thread Peter J. Holzer
On 2019-07-10 08:57:29 -0400, kamaraju kusumanchi wrote:
> Given a csv file with the following contents
> 
> 20180701, A
> 20180702, A, B
> 20180703, A, B, C
> 20180704, B, C
> 20180705, C
> 
> I would like to transform the underlying data into a dataframe such as
> 
> date, A, B, C
> 20180701,  True, False, False
> 20180702,  True,  True, False
> 20180703,  True,  True,  True
> 20180704, False,  True,  True
> 20180705, False, False,  True
> 
> the idea is that the first field in each line of the csv is the row
> index of the dataframe. The subsequent fields will be its column names
> and the values in the dataframe tell whether that element is present
> or not in the line.
> 
> Is there a name for this transformation?

This type of output is usually called a cross table, but I don't know
whether this specific transformation has a name (if you had only one of
A, B, and C per line it would be a kind of pivot operation).

> Any existing code/library
> that can transform data back and forth between the two formats? I can
> write one myself if there is none but trying to avoid reinventing the
> wheel if possible.

I need to produce cross tables frequently, but I never bothered to make
it into the library because the part that is common (maintaining two
hashes and dumping them) is so much less than the parts which are
different (data source and format, what information to extract, output
format).

The basic idea is that you use a dict of dict of (whatever) to represent
your output matrix: row keys are the first level, column keys are the
second level. Cell type in your case is bool, so you could use a set
instead of a dict of bool. Often you want to keep information about each
row (e.g. order of appearance, or a count), so you'll use a second dict
for that. For output you get a list of columns in the right order and
then iterate over the 1st level keys of your dict and the list of
columns to access each cell.

hp


-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | [email protected] | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difficulties configuring LTO on macOS with clang

2019-07-10 Thread Barry Scott



> On 10 Jul 2019, at 15:25, Scott Colby  wrote:
> 
> Unfortunately that path is absent on my system. Could the issue be that the 
> llvm version of ar is not present at all on macOS? What remains confusing in 
> that case is that by using CC=cc (and I assume just ar) the LTO compilation 
> succeeds, despite cc being a symlink to clang anyway.

Oh that may be because I have MacPorts installed on my mac
I guess you have macPorts installed as well?

I see you are using brew openssl. Maybe the macPorts tools
and the brew tools are conflicting?

What if you remove /opt/local/bin from your PATH does that help configure find 
the tools it needs?

Barry




> 
> Thanks,
> Scott
> 
> On Tue, Jul 9, 2019, at 15:39, Barry Scott wrote:
>> 
>> 
>> > On 9 Jul 2019, at 19:28, Scott Colby  wrote:
>> > 
>> > Hello all,
>> > 
>> > I am having difficulty building Python with `--with-lto` on macOS 10.14.5. 
>> > With a clean checkout of the CPython source at the tagged release for 
>> > 3.7.4, I ran:
>> > 
>> > $ ./configure --prefix=/opt/python3.7.4 --enable-optimizations 
>> > --enable-ipv6 --with-lto --with-openssl=$(brew --prefix openssl) CC=clang
>> > checking for git... found
>> > checking build system type... x86_64-apple-darwin18.6.0
>> > checking host system type... x86_64-apple-darwin18.6.0
>> > checking for python3.7... python3.7
>> > checking for --enable-universalsdk... no
>> > checking for --with-universal-archs... no
>> > checking MACHDEP... checking for --without-gcc... no
>> > checking for --with-icc... no
>> > checking for gcc... clang
>> > checking whether the C compiler works... yes
>> > checking for C compiler default output file name... a.out
>> > checking for suffix of executables...
>> > checking whether we are cross compiling... no
>> > checking for suffix of object files... o
>> > checking whether we are using the GNU C compiler... yes
>> > checking whether clang accepts -g... yes
>> > checking for clang option to accept ISO C89... none needed
>> > checking how to run the C preprocessor... clang -E
>> > checking for grep that handles long lines and -e... /usr/bin/grep
>> > checking for a sed that does not truncate output... /usr/bin/sed
>> > checking for --with-cxx-main=... no
>> > checking for clang++... no
>> > configure:
>> > 
>> >  By default, distutils will build C++ extension modules with "clang++".
>> >  If this is not intended, then set CXX on the configure command line.
>> > 
>> > checking for the platform triplet based on compiler characteristics... 
>> > darwin
>> > checking for -Wl,--no-as-needed... no
>> > checking for egrep... /usr/bin/grep -E
>> > checking for ANSI C header files... yes
>> > checking for sys/types.h... yes
>> > checking for sys/stat.h... yes
>> > checking for stdlib.h... yes
>> > checking for string.h... yes
>> > checking for memory.h... yes
>> > checking for strings.h... yes
>> > checking for inttypes.h... yes
>> > checking for stdint.h... yes
>> > checking for unistd.h... yes
>> > checking minix/config.h usability... no
>> > checking minix/config.h presence... no
>> > checking for minix/config.h... no
>> > checking whether it is safe to define __EXTENSIONS__... yes
>> > checking for the Android API level... not Android
>> > checking for --with-suffix...
>> > checking for case-insensitive build directory... yes
>> > checking LIBRARY... libpython$(VERSION)$(ABIFLAGS).a
>> > checking LINKCC... $(PURIFY) $(MAINCC)
>> > checking for GNU ld... no
>> > checking for --enable-shared... no
>> > checking for --enable-profiling... no
>> > checking LDLIBRARY... libpython$(VERSION)$(ABIFLAGS).a
>> > checking for ar... ar
>> > checking for readelf... no
>> > checking for a BSD-compatible install... /usr/local/bin/ginstall -c
>> > checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p
>> > checking for --with-pydebug... no
>> > checking for --with-assertions... no
>> > checking for --enable-optimizations... yes
>> > checking for --with-lto... yes
>> > checking target system type... x86_64-apple-darwin18.6.0
>> > checking for -llvm-ar... no
>> > checking for llvm-ar... ''
>> > configure: error: llvm-ar is required for a --with-lto build with clang 
>> > but could not be found.
>> 
>> I see /opt/local/bin/llvm-ar-mp-4.0 which ends up running the llvm-ar from 
>> /opt/local/libexec/llvm-4.0/bin
>> 
>> Just a guess but maybe you need to add /opt/local/libexec/llvm-4.0/bin/ to 
>> your path
>> as its where llvm-ar is.
>> 
>> Barry
>> 
>> > 
>> > If I change the command to `... CC=cc` configuration appears to happen 
>> > normally.
>> > 
>> > On my version of macOS, cc is a symlink to clang.
>> > 
>> > Why is this happening? What should I be doing differently to explicitly 
>> > specify clang as my compiler?
>> > 
>> > Thank you,
>> > Scott Colby
>> > -- 
>> > https://mail.python.org/mailman/listinfo/python-list
>> > 

-- 
https://mail.python.org/mailman/listinfo/python-list


How Do You Replace Variables With Their Values?

2019-07-10 Thread CrazyVideoGamez
How do you replace a variable with its value in python 3.7.2? For example, say 
I have:

dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main Course':['Fish', 
'Meat'], 'Desert':['Cake', 'Banana Split']}

# Don't ask where I got the dinner from

for meal in dinner.keys():
meal = list(dinner[meal]

But I only get one list called "meal" and I'm just changing it with the code 
above (you can find that by printing it out). How can I make separate lists 
called 'Starters', 'Main Course', and 'Desert'? 
-- 
https://mail.python.org/mailman/listinfo/python-list


How Do You Replace Variables With Their Values?

2019-07-10 Thread CrazyVideoGamez
How do you replace a variable with its value in python 3.7.2? For example, say 
I have: 

dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main Course':['Fish', 
'Meat'], 'Desert':['Cake', 'Banana Split']} 

# Don't ask where I got the dinner from

for meal in dinner.keys():
meal = list(dinner[meal])

But I only get one list called "meal" and I'm just changing it with the code 
above (you can find that by printing it out). How can I make separate lists 
called 'Starters', 'Main Course', and 'Desert'?
-- 
https://mail.python.org/mailman/listinfo/python-list


load extention spatialite in sqlite on windows

2019-07-10 Thread MICHAEL LANE via Python-list
Hi,
 
I tried to reproduce 
this(https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html) in 
windows. How can I do that?

I'm using Windows 10, my project use Pyramid Framework with Python 3.6.8.

Even though I put the dll file in a directory defined in %PATH% or try 
with/without full path, with/without file extension, with '//' or '\', with 
libspatialite-4.dll or using excute with all combination mentionned before... 
dbapi_conn.execute("SELECT load_extension('mod_spatialite.dll')")


For example i tried this kind of combinaison:

def load_spatialite(dbapi_conn, connection_record):
 dbapi_conn.load_extension('C:\\mydll\\mod_spatialite.dll') # 
dbapi_conn.load_extension('C:\\mydll\\libspatialite-4.dll')
 # dbapi_conn.load_extension('mod_spatialite')
 # dbapi_conn.load_extension('mod_spatialite.dll')
 # dbapi_conn.execute("SELECT load_extension('C:\\mydll\\mod_spatialite.dll')")
 # dbapi_conn.execute("SELECT load_extension('mod_spatialite.dll')") # 
dbapi_conn.execute("SELECT load_extension('mod_spatialite')") # 
dbapi_conn.load_extension('C:/mydll\mod_spatialite.dll')


Can make it work, always getting:
dbapi_conn.load_extension('C:\\mydll\\mod_spatialite.dll')sqlalchemy.exc.OperationalError:
 (sqlite3.OperationalError) OsError 0xc1 (193)
(Background on this error at: http://sqlalche.me/e/e3q8)
( 
'http://www.google.com/url?qdhttp%3A%2F%2Fsqlalche.me%2Fe%2Fe3q8sadDsntzd1usgdAFQjCNERkh6zEzVSQLk5naEvDfK-IlHbLg';return
 true;" 
onmousedown="this.href='http://www.google.com/url?qdhttp%3A%2F%2Fsqlalche.me%2Fe%2Fe3q8sadDsntzd1usgdAFQjCNERkh6zEzVSQLk5naEvDfK-IlHbLg';return
 true;" style="CURSOR: pointer; TEXT-DECORATION: none; BORDER-TOP: 0px; 
BORDER-RIGHT: 0px; BORDER-BOTTOM: 0px; COLOR: rgb(102,17,204); PADDING-BOTTOM: 
0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; BORDER-LEFT: 0px; 
PADDING-RIGHT: 0px" href="http://sqlalche.me/e/e3q8)" rel=nofollow 
target=_blank) 
 
I've been told to use import sqlite3 so I make it a try with this code:
 
 
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.load_extension('c:\\mydll\\mod_spatialite') Try too with 
'c:/mydll/mod_sptatialite' But I got the same error.



conn.load_extension('c:\\mydll\\mod_spatialite')
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) OsError 0xc1 (193)
(Background on this error at: http://sqlalche.me/e/e3q8)

 
 

My directory contain the unzip of: 
http://www.gaia-gis.it/gaia-sins/windows-bin-x86/mod_spatialite-4.3.0a-win-x86.7z
The directory is set in %PATH%

Any hint will be appreciated.


Thanks
 
 
Michael
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: load extention spatialite in sqlite on windows

2019-07-10 Thread Chris Angelico
On Thu, Jul 11, 2019 at 8:57 AM MICHAEL LANE via Python-list
 wrote:
>
> conn.load_extension('c:\\mydll\\mod_spatialite')
> sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) OsError 0xc1 (193)
> (Background on this error at: http://sqlalche.me/e/e3q8)
>

Seems this is SQLite's way of throwing up its arms and saying "I have
no idea what went wrong". The error code 0xC1 or 193 decimal can be
interpreted from Microsoft's documentation:

https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
"""
ERROR_BAD_EXE_FORMAT

193 (0xC1)

%1 is not a valid Win32 application.
"""

I would guess that this is referring to the DLL itself (it might not
be, but that's a good place to start), and the first thing I'd do is
check if it's even a Windows DLL file - maybe something broke in the
download or something. If it looks like a legit file, the next thing
I'd look at is whether it's a 32-bit or 64-bit DLL; you have to match
the word size of your SQLite binary.

Unfortunately SQLite didn't give much info, so we're a bit in the dark
here. This may require some research.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How Do You Replace Variables With Their Values?

2019-07-10 Thread Terry Reedy

On 7/10/2019 6:37 PM, CrazyVideoGamez wrote:

the below twice.  Please post just once and be patient for at least a 
couple of hours -- or days if not subscribed.



How do you replace a variable with its value in python 3.7.2?


Use the variable (name) in an expression.  But this is not what you ask 
below.




For example, say I have:

dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main Course':['Fish', 
'Meat'], 'Desert':['Cake', 'Banana Split']}

# Don't ask where I got the dinner from


I think most of us have seen examples like this in programming books.


for meal in dinner.keys():
 meal = list(dinner[meal]

But I only get one list called "meal"


Because it is just one identifier, and you rebind it to multiple values.


and I'm just changing it with the code above (you can find that by printing it 
out). How can I make separate lists called 'Starters', 'Main Course', and 
'Desert'?


starters = dinner['Starters']
main_course = dinner['Main Course']
desert = dinner['Desert']

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Problem to delete or modify

2019-07-10 Thread Hla Kyi via Python-list
Dear Sir/ Madam,
    1. I try to modify, some of the check boxes can not be selected.    2. I 
try to uninstall, "successfully uninstall" message is come out. When I exit it 
"if you have any problem, please contact  [email protected] " message is 
come out.     I install Python 3.7.2 at my laptop in Windows 10 operating 
system.
Best Regards,
Kyi 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How Do You Replace Variables With Their Values?

2019-07-10 Thread Ben Finney
Terry Reedy  writes:

> On 7/10/2019 6:37 PM, CrazyVideoGamez wrote:
>
> > and I'm just changing it with the code above (you can find that by
> > printing it out). How can I make separate lists called 'Starters',
> > 'Main Course', and 'Desert'?
>
> starters = dinner['Starters']
> main_course = dinner['Main Course']
> desert = dinner['Desert']

The question comes, though, why you (CrazyVideoGamez) are doing this.

You have the lists immediately accesible as dictionary elements, by
name.

Why do you need to also have them bound to separate names; what problem
are you trying to solve that you think this will help?

-- 
 \   “If [a technology company] has confidence in their future |
  `\  ability to innovate, the importance they place on protecting |
_o__) their past innovations really should decline.” —Gary Barnett |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How Do You Replace Variables With Their Values?

2019-07-10 Thread Frank Millman

On 2019-07-11 12:43 AM, CrazyVideoGamez wrote:

How do you replace a variable with its value in python 3.7.2? For example, say 
I have:

dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main Course':['Fish', 
'Meat'], 'Desert':['Cake', 'Banana Split']}

# Don't ask where I got the dinner from

for meal in dinner.keys():
 meal = list(dinner[meal])

But I only get one list called "meal" and I'm just changing it with the code 
above (you can find that by printing it out). How can I make separate lists called 
'Starters', 'Main Course', and 'Desert'?



1. Iterating over a dictionary returns each key. So instead of 'for meal 
in dinner.keys()' you can just say 'for meal in dinner'.


2. It is not a good idea to use the variable name 'meal' for two 
purposes. You use it to get each key, and then it gets over-ridden with 
the result of 'list(dinner[meal])'. Then on the next iteration it gets 
over-ridden again with the next key.


3. The result of 'dinner[meal]' is already a list, so there is no need 
to say 'list(dinner[meal])'. Technically there is a difference - your 
approach creates a new list, instead of just creating a reference to the 
original one, but I doubt if that was your intention.


4. There is potentially more than one list, but for each iteration you 
over-ride the previous one, so at the end, only the last one remains. 
The solution is to create a 'list of lists'.


Putting all this together -

courses = []
for course in dinner:
courses.append(dinner[course])

This gives you a list, called 'courses', containing three lists, one for 
each 'course' containing the options for that course.


However, in the process, you have lost the names of the courses, namely 
'Starters', 'Main course', and 'Desert'.


So to answer your original question "How can I make separate lists 
called 'Starters', 'Main Course', and 'Desert'?", the code that you 
started with is exactly what you asked for.


I think you were asking how to create a variable called 'Starters' 
containing the list of starters. It can be done, using the built-in 
function 'setattr()', but I don't think that would be useful. If you 
knew in advance that one of the options was called 'Starters', you could 
just say Starters = ['Fried Calamari', 'Potted crab']. But if you did 
not know that in advance, how would you know what your variable was called?


Frank Millman

--
https://mail.python.org/mailman/listinfo/python-list