Re: [Tutor] Contour Plots

2018-08-28 Thread boB Stepp
Welcome Tara!

On Tue, Aug 28, 2018 at 6:46 PM Tara 38  wrote:
>
> Hi,
>
>
> I wonder if someone can give me some advice? I need to build a contour plot 
> (ideally with Seaborn) in python. The plot would document text data. I cannot 
> work out how I need to convert the data file (currently csv file) so that I 
> have 3 variables that I can then plot as a contour map and visualize in 
> Seaborn.
>
>
> Really stuck as to where to even start.

You really did not give many details or your Python background and
knowledge, so it is difficult to know exactly what you need help with.
But from your description as is, it sounds like your immediate problem
is extracting data from your csv file.  Python 2 and 3 have a csv
module to facilitate handling this type of file.  The Python 3 docs
for it are at https://docs.python.org/3/library/csv.html  A Python csv
tutorial (after Googling) can be found at
https://www.blog.pythonlibrary.org/2014/02/26/python-101-reading-and-writing-csv-files/
 There are many others you can find via a search if you don't like
that one.

If your problems lie with generating Seaborn plots another search
found their official tutorial at
https://seaborn.pydata.org/tutorial.html

If the above does not sufficiently help then you will have to provide
additional information as to what exactly you are trying to do, how
are you trying to do it, where are you getting stuck, etc.

HTH!
-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Contour Plots

2018-08-28 Thread Tara 38
Hi,


I wonder if someone can give me some advice? I need to build a contour plot 
(ideally with Seaborn) in python. The plot would document text data. I cannot 
work out how I need to convert the data file (currently csv file) so that I 
have 3 variables that I can then plot as a contour map and visualize in Seaborn.


Really stuck as to where to even start.


Thanks,


Tara



[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png]
 Virus-free. 
www.avg.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem compiling code from GitHub

2018-08-28 Thread Dave Hill

I did as suggested but with the same result.

I am now looking at extracting the code from the the separate files to 
form a single module, and hopefully get a result.


On 27/08/2018 14:14, Steven D'Aprano wrote:

Hi Dave, and welcome!


On Mon, Aug 27, 2018 at 12:14:33PM +0100, Dave Hill wrote:


I have found 'odswriter' on GitHub
https://github.com/mmulqueen/odswriter which appears to provide what I
want. However, I have come to a halt, due to the limitation of my knowledge.

[...]



I get the following error

Traceback (most recent call last):
   File "C:\Code\Python\ODS_Writer\Test_ODS#1.py", line 5, in 
     from OdsWriter import odswriter as ods
   File "C:\Code\Python\ODS_Writer\OdsWriter.py", line 7, in 
     from . import ods_components
ImportError: attempted relative import with no known parent package

I have put the code from GitHub in various locations

That sounds like the problem. Some libraries are pretty forgiving about
where they are, some not so much. Some come with detailed installation
instructions, some don't.

This appears to be in the second category of both cases.

I would start by carefully deleting the code from Github (or at least
moving it out of the way) first, then installing it again.

Try installing it using the pip command. Open up a command line console.
I think you do this under Windows by typing Ctrl-R ("Run") then entering
"cmd", You ought to get a text window with a prompt looking something
like this:

 C:\ %

or similar. (If in doubt, ask.)

Try entering the command

 pip --version

and if you get an error like "pip not found" or similar, try this:

python36 -m ensurepip --default-pip
python36 -m pip install --upgrade pip setuptools wheel

after which you can then try:

pip install odswriter

I'll be honest: I don't use pip myself, every time I've tried I get
frustrated and end up installing things the old-fashioned manual way
which is theoretically "harder" but it works for me. And everyone else
swears by pip. (I just swear at it, especially the horrible colours it
likes to use.)

But if you get any errors, please don't hesitate to copy and paste them
here (DON'T take a screen shot) so we can read them and advise you.


There's a tutorial here with more detail:

https://packaging.python.org/tutorials/installing-packages/





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help generating table of contents

2018-08-28 Thread Albert-Jan Roskam
From: Tutor  on behalf of 
Peter Otten <__pete...@web.de>
Sent: Monday, August 27, 2018 6:43 PM
To: tutor@python.org
Subject: Re: [Tutor] need help generating table of contents
  

Albert-Jan Roskam wrote:

> 
> From: Tutor  on behalf
> of Peter Otten <__pete...@web.de> Sent: Friday, August 24, 2018 3:55 PM
> To: tutor@python.org
> 
>> The following reshuffle of your code seems to work:
>> 
>> print('\r\n** Table of contents\r\n')
>> pattern = '/Title \((.+?)\).+?/Page ([0-9]+)(?:\s+/Count ([0-9]+))?'
>> 
>> def process(triples, limit=None, indent=0):
>> for index, (title, page, count) in enumerate(triples, 1):
>> title = indent * 4 * ' ' + title
>> print(title.ljust(79, ".") + page.zfill(2))
>> if count:
>> process(triples, limit=int(count), indent=indent+1)
>> if limit is not None and limit == index:
>>  break
>> 
>> process(iter(re.findall(pattern, toc, re.DOTALL)))
> 
> Hi Peter, Cameron,
> 
> Thanks for your replies! The code above indeeed works as intended, but: I
> don't really understand *why*. I would assign a name to the following line
> "if limit is not None and limit == index", what would be the most
> descriptive name? I often use "is_*" names for boolean variables. Would
> "is_deepest_nesting_level" be a good name?



> No, it's not necessarily the deepest level. Every subsection eventually ends 
> at this point; so you might call it reached_end_of_current_section
> 
> Or just 'limit' ;) 

LOL. Ok, now I get it :-)

> The None is only there for the outermost level where no /Count is provided. 
> In this case the loop is exhausted.
> 
> If you find it is easier to understand you can calculate the outer count aka 
> limit as the number of matches - sum of counts:
> 



>> Also, I don't understand why iter() is required here, and why finditer()
> >is not an alternative.

>finditer() would actually work -- I didn't use it because I wanted to make 
> as few changes as possible to your code. What does not work is a list like 
>the result of findall(). This is because the inner for loops (i. e. the ones 
>in the nested calls of process) are supposed to continue the iteration 
>instead of restarting it. A simple example to illustrate the difference:

Ah, the triples cannot be unpacked inside the "for" line of the loop. This 
works:
def process(triples, limit=None, indent=0):
 for index, triple in enumerate(triples, 1):
 title, page, count = triple.groups()  # unpack it here
 title = indent * 4 * ' ' + title
 print(title.ljust(79, ".") + page.zfill(2))
 if count:
 process(triples, limit=int(count), indent=indent+1)
 if limit is not None and limit == index:
 break

process(re.finditer(pattern, toc, re.DOTALL))


If I don't do this, I get this error:
  File "Q:/toc/toc.py", line 64, in 
process(re.finditer(pattern, toc, re.DOTALL))
  File "Q:/Ctoc/toc.py", line 56, in process
for index, (title, page, count) in enumerate(triples, 1):
TypeError: '_sre.SRE_Match' object is not iterable

Process finished with exit code 1


Thanks again Peter! Very insightful!

Albert-Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to have unique identifiers for multiple object instances of a given class?

2018-08-28 Thread Alan Gauld via Tutor
On 28/08/18 02:53, boB Stepp wrote:

> Wouldn't a single JSON file be wasteful?  If I used this program for a
> couple of years or so and habitually played a lot of solitaire, that
> would be a lot of stuff to load into RAM when on any given solitaire
> session I might only play one to three kinds of solitaire.  

It shouldn't be any more wasteful than if you used separate files.
Either you have to load up every file you ever saved or you have
some criteria that prevents you loading all of them. The same
with a JSON file. Either you load every record in the file or
you have some criteria that lets you load a subset.

You might want to eventually have some kind of archive
function that offloads old games to a separate file, just to
keep initial load times down but that's probably not an issue
in the short term.

> perhaps I am misunderstanding JSON's capabilities as I only have a
> cursory knowledge of it from considering it for other projects.

Think of it like a file based dictionary. You only instantiate
the objects you need. You load objects based on the key.

How you identify which objects you need at startup is the clever
bit. You haven't told us enough about your workflow for us to
suggest a solution there. But the same issue applies whether
you use separate files per game or session or a single JSON file.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor