Re: [Tutor] Collating date data from a csv file

2019-05-08 Thread boB Stepp
On Wed, May 8, 2019 at 10:29 PM boB Stepp  wrote:
>
> On Wed, May 8, 2019 at 10:09 PM Cameron Simpson  wrote:
> >
> > A defaultdict is a dict which magicly makes missing elements when they
> > get access, using a factory function you supply. Here we're using "int"
> > as that factory, as int() returns zero.
>
> Is int() guaranteed to always return zero as Python versions progress?
>  More importantly, perhaps, where would I go to look to find the
> answer to this question myself?

It must be time to go to bed!  Somehow my eyes missed the int() return
behavior at https://docs.python.org/3/library/functions.html#int my
first time through.  Sorry for the noise!

> boB



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


Re: [Tutor] Collating date data from a csv file

2019-05-08 Thread boB Stepp
On Wed, May 8, 2019 at 10:09 PM Cameron Simpson  wrote:
>
> A defaultdict is a dict which magicly makes missing elements when they
> get access, using a factory function you supply. Here we're using "int"
> as that factory, as int() returns zero.

Is int() guaranteed to always return zero as Python versions progress?
 More importantly, perhaps, where would I go to look to find the
answer to this question myself?


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


Re: [Tutor] Collating date data from a csv file

2019-05-08 Thread Cameron Simpson

On 08May2019 21:04, Dave Hill  wrote:
I have a csv file which details the results of equipment tests, I 
carry out PAT testing as a volunteer at a heriatge railway in N. 
Wales. I want to extract how many items were tested on each test day. 
So far I have generated a List of test dates, but I am now stalled at 
how to efficiently count numbers tested on each date.


Can I have a list of tuples, where one item is the date and the second 
the count?


Not as such, because you can't modify a tuple (so you can't update the 
count part). But you could use a 2 element list.



or is there a better construct?


Oh definitely. The easiest thing would be a defaultdict(int). Example:

 from collections import defaultdict
 ...
 by_date = defaultdict(int)
 for row in csvdata:
   timestamp = row[1]  # based on your example data
   # get the date from the timestamp
   date = ...
   by_date[date] += 1

A defaultdict is a dict which magicly makes missing elements when they 
get access, using a factory function you supply. Here we're using "int" 
as that factory, as int() returns zero.


I presume you've got the timestamp => date conversion sorted?

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


[Tutor] Collating date data from a csv file

2019-05-08 Thread Dave Hill
I have a csv file which details the results of equipment tests, I carry 
out PAT testing as a volunteer at a heriatge railway in N. Wales. I want 
to extract how many items were tested on each test day. So far I have 
generated a List of test dates, but I am now stalled at how to 
efficiently count numbers tested on each date.


Can I have a list of tuples, where one item is the date and the second 
the count?


or is there a better construct?

Thanks in advance,

Dave

For completeness, I have listed below an extract from a target file, 
where the 10 digit number is the UNIX timestamp


182 1515001232
Toaster 13  20001
183 1515001259     Contact Grill13  20001
245 1515001367
3G Cube Adaptor 13  0   1
246 1515001396      13A IEC Lead5   0   1
248 1515001415
Worktop Light   3   30  1
420 1515001440
Fly killer  0   0   1
424 1515001461
Dairy fridge13  0   1
427 1513277293     Fire 13  0   1
429 1515001489
Toaster Avanti  13  0   1

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


Re: [Tutor] Can't reinstall pip for Python 3.7.3

2019-05-08 Thread Mats Wichmann
On 5/8/19 5:36 AM, Zelphy wrote:
> Dear tutor members,
> 
> After spending a lot of time on forums trying to fix this problem, I come
> here hoping for a solution to my problem.
> In fact, after upgrading my version of Python ( I was on 3.6.5 and then on
> 3.7.3 ) I wanted to reinstall pip ( mainly in order to download Pygame )
> But, after downloading Python and the get-pip.py file, when I open it ( and
> it do the same thing every time ) the command prompt tell me "successfully
> uninstalled pip-19.1.1 and then Python stop to work.
> [image: Pip install.PNG]
> I checked the Path but when I open the Script folder, this folder is empty.
> But as I remember, normally there is, in this folder, a pip.exe and some
> other things.
> 
> [image: Path.PNG]
> 
> [image: path Environment variables.PNG]
> 
> I also linked here some screenshots that might help.

Screenshots don't usually make it through the mailing list software.

When installing Python on Windows, you don't need to install pip, so
don't fiddle with the get-pip instructions - it looks like you had it,
then it was uninstalled but not reinstalled.  Just avoid that.

If you do a fresh install and check, it should all be there. The only
thing is that the Scripts directory doesn't go into your environment
path, even if you said to add the path for Python.

Instead of fiddling with that, and assuming you installed the python
launcher (which is a good idea), invoke pip as a module instead of
trying to use pip.exe.  Here's to check if it's working at all:

py -m pip --version

here's to install something:

py -m pip install MyFavoritePackage


If you then need to _upgrade_ pip, you would do it this way:

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


[Tutor] Can't reinstall pip for Python 3.7.3

2019-05-08 Thread Zelphy
Dear tutor members,

After spending a lot of time on forums trying to fix this problem, I come
here hoping for a solution to my problem.
In fact, after upgrading my version of Python ( I was on 3.6.5 and then on
3.7.3 ) I wanted to reinstall pip ( mainly in order to download Pygame )
But, after downloading Python and the get-pip.py file, when I open it ( and
it do the same thing every time ) the command prompt tell me "successfully
uninstalled pip-19.1.1 and then Python stop to work.
[image: Pip install.PNG]
I checked the Path but when I open the Script folder, this folder is empty.
But as I remember, normally there is, in this folder, a pip.exe and some
other things.

[image: Path.PNG]

[image: path Environment variables.PNG]

I also linked here some screenshots that might help.




Btw I'm not a native english speaker so I've may done some mistakes and I'm
sorry about that.

Hopping to have a solution to this problem,

Best regards


Garanti
sans virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor