Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 09:23 20 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Anyone know Python?

     Page 3 of 3    
Author Message
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 05:30am 01 May 2021
Copy link to clipboard 
Print this post

Python is famous (infamous?) for its anal attention to matters of code style and formatting - according to "The Zen of Python", there is usually "one best way" to do anything, including formatting code for maximum clarity and readability.

I haven't used this personally yet, but a colleague just turned me on to Black, which is emerging as a popular Python code prettifier and formatter. My hunch is it could also untangle logic errors arising from whitespace issues.

I guess the name is a riff on Henry Ford's "any color you want, as long as it's black" Model T, or maybe Spinal Tap's "none more black" album.

P.S. I just picked up a handful of Raspberry Picos (at $5 a pop, why not?), and having lots of fun at the moment with MicroPython making LEDs blink and buzzers buzz! Frankly, I am in awe at the flawless launch of this product, and the huge amounts of quality documentation and developer boards / tools / support for the RP2040 in such a short time. Definitely something to keep your eye on if you are an MCU and/or Python enthusiast.
Edited 2021-05-01 15:36 by RetroJoe
Enjoy Every Sandwich / Joe P.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1421
Posted: 04:49pm 01 May 2021
Copy link to clipboard 
Print this post

  RetroJoe said  
P.S. I just picked up a handful of Raspberry Picos (at $5 a pop, why not?)


US$ 9 is the lowest cost I've found (including shipping).
Micromites and Maximites! - Beginning Maximite
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 02:41pm 02 May 2021
Copy link to clipboard 
Print this post

Does anyone know how to limit the number of items added to a csv file in Python?
I'm trying to make a graph and to do it I made a csv file that adds values to it every minute
I need the csv file to only add 30 times then loop so it always saves the last 30 reads
like windspeed every minute it writes it to the csv file but I want it to always only have the last 30 minutes worth of windspeed in there.

This is my csv datafile, at the moment it keeps adding till it gets to

CSVFILENAME = 'data.csv'
CSV_FILE_MAX_BYTES = 2048*2048 #Max. size of logfile before rotating.
CSVFILENAME = 'data.csv'
#every minute write these values
csvfile=open('data.csv','a', newline='\n') #Write Data for graph to CSV
obj=csv.writer(csvfile)
now=datetime.now()
readings=[(now.strftime("%a")) , (now.strftime("%H:%M")) ,(Data.temphigh) , (Data.templow)  , (Data.sea_level_pressure) , (Data.relative_humidity), (round(Data.wind,2)) , (round(Data.gust,2))]
obj=csv.writer(csvfile)
obj.writerow(readings)
csvfile.close()
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 03:08pm 02 May 2021
Copy link to clipboard 
Print this post

  CircuitGizmos said  
  RetroJoe said  
P.S. I just picked up a handful of Raspberry Picos (at $5 a pop, why not?)


US$ 9 is the lowest cost I've found (including shipping).


I ordered mine from Canakit  

Unit price was CAD 5.25, but indeed, with shipping and taxes it is around ten bucks each.

Still not going to break the bank, but there is definitely something funky with a business model where the shipping cost is approximately the same as the price of the merchandise!



Enjoy Every Sandwich / Joe P.
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 03:16pm 02 May 2021
Copy link to clipboard 
Print this post

@Lew247, there are Python classes explicitly for log handling

Otherwise, I'm guessing you will need to do the "handling" yourself by counting the number of written records and comparing it to your threshold.
Enjoy Every Sandwich / Joe P.
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 705
Posted: 03:22pm 02 May 2021
Copy link to clipboard 
Print this post

>> the shipping cost is approximately the
>> same as the price of the merchandise!

Signs of the times  
All these mass produced boards
are becoming cheaper ...
my site
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 04:08pm 02 May 2021
Copy link to clipboard 
Print this post

@RetroJoe

Spinal Tap:

"I do not, for one, think that the problem was that the band was down. I think that the problem may have been, that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf. Alright? That tended to understate the hugeness of the object." -- David St. Hubbins

   
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 10:08pm 02 May 2021
Copy link to clipboard 
Print this post

  hitsware2 said  >> the shipping cost is approximately the
>> same as the price of the merchandise!

Signs of the times  
All these mass produced boards
are becoming cheaper ...


I suppose, but there is also some good old-fashioned profiteering going on. These devices are tiny and feather-light, and much heavier items ship direct from China for much cheaper.

In other words, Canakit is most definitely making a healthy margin on shipping these domestically. That's their prerogative, but my point (and Gizmo's) is there is apparently no place on Earth you can buy a Pico for the highly-touted $4 price point.
Enjoy Every Sandwich / Joe P.
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 10:29pm 02 May 2021
Copy link to clipboard 
Print this post

  Tinine said  @RetroJoe

Spinal Tap:

"I do not, for one, think that the problem was that the band was down. I think that the problem may have been, that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf. Alright? That tended to understate the hugeness of the object." -- David St. Hubbins

   


Great dialogue, almost all of it ad-libbed ("What's wrong with being sexy?"). Without a doubt the best mockumentary ever, even if you include Christoper Guest's later works.

What's awesome is you're never sure who or what the target of the mocking is - I think if I had to pick, it is "pretentiousness" in all its forms - almost every character is a pompous ass.

Re the Stonehenge production number and song, I'm almost certain it's Jethro Tull they are ridiculing, arguably the most pretentious British "art rock" group in history... starting with the name of the band. Still,  Martin Barre's guitar solo in "Aqualung" has stood the test of time - easily in my Top Ten list.

For the electro-geeks on this forum, may all your projects "go to 11" :)
Enjoy Every Sandwich / Joe P.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5883
Posted: 10:47pm 02 May 2021
Copy link to clipboard 
Print this post

  RetroJoe said  
In other words, Canakit is most definitely making a healthy margin on shipping these domestically. That's their prerogative, but my point (and Gizmo's) is there is apparently no place on Earth you can buy a Pico for the highly-touted $4 price point.


In January I paid $5.75AU which at the time was just about spot on $4US
Freight was also not too bad for AU.



Jim
VK7JH
MMedit   MMBasic Help
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 07:57am 06 May 2021
Copy link to clipboard 
Print this post

https://www.theregister.com/2021/05/05/aws_chalice_python/
 
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 375
Posted: 08:21am 06 May 2021
Copy link to clipboard 
Print this post

I bought two for about AU$5 each, sad hype-worshipping loser me !!
Anyway they are free with this magazine :
hackspace
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024