[Tutor] Next steps after creating virtualenv (new github project)?
Hello, I want to execute: print('Hello world.') in a file called hello.py After creating a virtual-env (via PyCharm) I have these directories: ./foo ./foo/venv ./foo/venv/lib ./foo/venv/lib/python3.6 ./foo/venv/lib/python3.6/site-packages ./foo/venv/include ./foo/venv/bin I want to store my small project in git and upload it to github later. What is the best practice for the directory layout? Are there (official) docs how to start a new project after creating the virtualenv? Regards, Thomas Güttler -- Thomas Guettler http://www.thomas-guettler.de/ I am looking for feedback: https://github.com/guettli/programming-guidelines ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] systemd
Hi, I am nearly ready for the new season on the Heritage railway I volunteer on and I am putting the final touches to a revamped 'runaway train' attraction in the museum. The last act is to get the code to auto-start on power up, and I thought that I would use 'systemd'. The code runs on a Raspberry Pi; via the GPIO: sensing an input, reed switch, and controlling three outputs; smoke machine, fan and vibrating floor. on activation a video is played, at 8 times real speed, which is viewed through a mock-up of a loco cab. I can run a program using: [Unit] Description=TestVideo Service After=multi-user.target [Service] Type=idle User=pi ExecStart=/bin/bash /home/pi/Code/testVideo.sh Restart=no RestartSec=0 [Install] WantedBy=multi-user.target where 'testVideo.sh' ## Dave Hill, 28/02/2019 # 2 = HDMI, 1 = headphones, 0 = Auto amixer cset numid=3 1 python3 /home/pi/Code/TestVideo#6.py CLIP0026.MP4 20 DEBUG exit 0 as I want to control the audio output, in this case direct audio to the Raspberry Pi stereo output. The program runs an infinite loop that can be exited by Cntrl-C I would like to take advantage of the 'restart' functionality, but I still wish to have a method of exiting i.e. Restart=always Is there a way in which I can have automatic restart but also have a way of exiting? Thanks in advance, Dave ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] systemd
On 03/03/2019 14:46, Dave Hill wrote: > on power up, and I thought that I would use 'systemd'. This is really a Linux question not Python so you might like to try the Mint forums too. They are usually pretty responsive. > [Service] > Type=idle > > User=pi > ExecStart=/bin/bash /home/pi/Code/testVideo.sh > > Restart=no > RestartSec=0 > where 'testVideo.sh' > > ## Dave Hill, 28/02/2019 > > # 2 = HDMI, 1 = headphones, 0 = Auto > amixer cset numid=3 1 > > python3 /home/pi/Code/TestVideo#6.py CLIP0026.MP4 20 DEBUG To be honest I'm surprised that works. I'd expected bash to interpret the # as a comment delimiter! But I tried it and it seems ok, you live and learn... > Is there a way in which I can have automatic restart but also have a way > of exiting? That's the Linux bit... :-) -- 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
Re: [Tutor] systemd
Thank you - registering with Linux Mint On 03/03/2019 16:01, Alan Gauld via Tutor wrote: On 03/03/2019 14:46, Dave Hill wrote: on power up, and I thought that I would use 'systemd'. This is really a Linux question not Python so you might like to try the Mint forums too. They are usually pretty responsive. [Service] Type=idle User=pi ExecStart=/bin/bash /home/pi/Code/testVideo.sh Restart=no RestartSec=0 where 'testVideo.sh' ## Dave Hill, 28/02/2019 # 2 = HDMI, 1 = headphones, 0 = Auto amixer cset numid=3 1 python3 /home/pi/Code/TestVideo#6.py CLIP0026.MP4 20 DEBUG To be honest I'm surprised that works. I'd expected bash to interpret the # as a comment delimiter! But I tried it and it seems ok, you live and learn... Is there a way in which I can have automatic restart but also have a way of exiting? That's the Linux bit... :-) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] systemd
On 03Mar2019 16:01, Alan Gauld wrote: On 03/03/2019 14:46, Dave Hill wrote: python3 /home/pi/Code/TestVideo#6.py CLIP0026.MP4 20 DEBUG To be honest I'm surprised that works. I'd expected bash to interpret the # as a comment delimiter! But I tried it and it seems ok, you live and learn... The octothorpe is only a comment marker at the start of a word. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] systemd
> On Mar 3, 2019, at 14:59, Cameron Simpson wrote: > > On 03Mar2019 16:01, Alan Gauld wrote: >> On 03/03/2019 14:46, Dave Hill wrote: >>>python3 /home/pi/Code/TestVideo#6.py CLIP0026.MP4 20 DEBUG >> >> To be honest I'm surprised that works. >> I'd expected bash to interpret the # as a comment delimiter! >> But I tried it and it seems ok, you live and learn... > > The octothorpe is only a comment marker at the start of a word. While it works, it’s usually a bad idea to use non alphanumeric characters for filenames. Naming it TestVideo6.py would be less prone to “weird things” happening down the road. — David Rock da...@graniteweb.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Variable change within library depending on user input.
Hey there everybody hope your doing great. I was here a few months ago and got pointed in the right direction very kindly by one of the tutors. Im a little stuck again now and have been researching for a while and can't come up with a solution to my problem. The below program is designed to take two user inputs, item purchase location and sale location and then to compare some dictionaries of those locations and calculate the most profitable item to buy. Initially i designed this to work with just two locations and am now struggling to add a third. Author : Harry O'Neill Program : Find most profitable sale between two trade hubs within the star citizen game client. Waste has been remove as it's literally garbage anyway. taking user information user_purchase_location = input("Were are you planning to buy your goods?").lower() user_sale_destination = input("Where are you planning to sell your goods?").lower() dicts of items available to buy and sell at locations along with UEC price. buying_olisar = {'Medical Supply': 17.01,} selling_olisar = {'Agricium': 25.60, 'Aluminum': 1.25, 'Beryl': 4.26, 'Chlorine': 1.57, 'Corundum': 2.53, 'Diamond': 6.90, 'Distilled Spirits': 4.95, 'Fluorine': 2.80, 'Gold': 6.07, 'Hydrogen': 1.02, 'Iodine': 0.41, 'Laranite': 28.91, 'Processed Food': 1.39, 'Quartz': 1.44, 'Scrap': 1.67, 'Stims': 3.40, 'Titanium': 8.27, 'Tungsten': 3.90,} buying_levski = {'Agricultural Supply': 1.11, 'Aluminum': 1.20, 'Hydrogen': 0.98, 'Iodine': 0.38, 'Quartz': 1.37,} selling_levski = {'Agricium': 25.60, 'Altruciatoxine': 11.63, 'Beryl': 4.25, 'Chlorine': 1.56, 'Corundum': 2.53, 'Diamond': 6.07, 'Distilled Spirits': 4.95, 'Fluorine': 2.80, 'Gold': 6.07, 'Laranite': 28.25, 'Medical Supply': 18.00, 'Processed Food': 1.38, 'Scrap': 1.68, 'Stims': 3.40, 'Titanium': 8.27, 'Tungsten': 3.90, 'Widdow': 24.00,} buying_arc_corp_mining_area_157 = {'Chlorine': 1.44, 'Flurine': 2.63, 'Hydrogen': 0.97, 'Iodine': 0.34} selling_arc_corp_mining_area_157 = {'Altruciatoxine': 11.80, 'distilled spirits': 4.95, 'medical suppies': 18.05, 'processed food': 1.36, 'stims': 3.40, 'Widdow': 24.0} Sorting the dict into ascending value instead of alphabetical sort_buying_olisar = sorted(buying_olisar, key=lambda tup: tup[1]) sort_selling_olisar = sorted(selling_olisar, key=lambda tup:(tup[1], tup[0])) sort_buying_levski = sorted(buying_levski, key=lambda tup: tup[1]) sort_selling_levski = sorted(selling_levski, key=lambda tup:(tup[1], tup[0])) sort_buying_arc_corp_mining_area_157 = sorted(buying_arc_corp_mining_area_157, key=lambda tup: tup[1]) sort_selling_arc_corp_mining_area_157 = sorted(selling_arc_corp_mining_area_157, key=lambda tup:(tup[1], tup[0])) picking two dicts (buy/sell) and filtering them to print only common elements. def common(curr, other): return set(curr.keys()).intersection(set(other.keys())) tradable_items = common(buying_levski, selling_olisar) calculating the prices between possible sales. prices = {k: selling_olisar[k] - buying_levski[k] for k in tradable_items} finding the most profitable material import operator most_profitable_resourse = max(prices.items(), key=operator.itemgetter(1))[0] profit_ammount = prices profit_sorted = (f'{profit_ammount[most_profitable_resourse]:.2f}') print("The most profitable item to buy at " + user_purchase_location + " is " + most_profitable_resourse + " and will make a net profit of " + profit_sorted + " per unit when sold at " + user_sale_destination + ".") The two areas i am struggling to alter to allow this to work with more than two locations are below tradable_items = common(buying_levski, selling_olisar) and prices = {k: selling_olisar[k] - buying_levski[k] for k in tradable_items} i need to have the variables to alter based on the user input where as currently they are fixed as buying/selling levski/olisar. I have tried to create a second variable as follows: user_purchase_location_1 = 'buying_'+user_purchase_location+'' user_sale_destination_1 = 'selling_'+user_sale_destination+'' these produce the correct information that could be used in the above two lines however when altered like this: def common(curr, other): return set(curr.keys()).intersection(set(other.keys())) tradable_items = common(user_purchase_location_1, user_sale_destination_1) calculating the prices between possible sales. prices = {k: user_sale_destination_1[k] - user_purchase_location_1[k] for k in tradable_items} However they produce this error that i am unsure how to resolve. Traceback (most recent call last): File "/home/floppypoppy/PycharmProjects/Star Citizen Trading Program/Star Citizen trading NEW.py", line 33, in tradable_items = common(user_purchase_location_1, user_sale_destination_1) File "/home/floppypoppy/PycharmProjects/Star Citizen Trading Program/Star Citizen trading NEW.py", line 32, in common return set(curr.keys()).intersection(set(other.keys()
Re: [Tutor] systemd
> On Mar 3, 2019, at 08:46, Dave Hill wrote: > > > I would like to take advantage of the 'restart' functionality, but I still > wish to have a method of exiting > > i.e. Restart=always > > Is there a way in which I can have automatic restart but also have a way of > exiting? > Maybe “always” is not what you want. If you use “on-failure" instead, it will restart in all cases except when it cleanly exits. From systemd.service manpage: https://manpages.debian.org/jessie/systemd/systemd.service.5.en.html "Setting this to on-failure is the recommended choice for long-running services, in order to increase reliability by attempting automatic recovery from errors. For services that shall be able to terminate on their own choice (and avoid immediate restarting), on-abnormal is an alternative choice.” You will also see a table of what each setting does, to help you pick the best option for your needs. You might also want to set the RestartSec to something other than zero. If you set it to something like 20 seconds, it would also give you time to manually disable the service if you needed to. — David Rock da...@graniteweb.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor