From rmlibre at riseup.net Sun Dec 1 18:44:18 2019 From: rmlibre at riseup.net (rmlibre at riseup.net) Date: Sun, 01 Dec 2019 15:44:18 -0800 Subject: [Tutor] GPG password entry automation help Message-ID: <109eab6fda0f06180a78f7aefaee03c1@riseup.net> I sent a request for help some months ago for automating commands sent to gpg2 to create Ed-25519 ECC keys on Linux systems. Joe responded with a very helpful solution. I implemented the solution, but then ran into another roadblock towards automation: The Ubuntu pin-entry dialog pops up asking for the password to encrypt the created key. I worked for a long while trying to re-figure out how to send the password through the GPG interface, but I just could not understand how to do it. So I used a wretched hack to avoid requiring user interaction: I used the pynput library to take control of the keyboard in a separate process and press enter several times until the dialog disappears. Ew. I would be incredibly grateful if someone had a full solution which uses GPG's native functionality for automating password entry as well as handling responses to the interactive terminal prompt. The constraints are: creating specifically Ed-25519 curve keys; a generalizable solution for further working with GPG's native functionality (not only a password entry solution for key creation). Optionally: A solution which doesn't save the created keys as system-wide (that aren't available on the system keyring). Here's the current code. Either a solution which tweaks this code, or something general which I'll have to implement, are totally welcome. >import subprocess >from time import sleep >from pynput import keyboard >from multiprocessing import Process > >class GnuPG: > def __init__(self, username, email, passphrase): > self.email = email > self.username = username > self.passphrase = passphrase > self._init_gpg_directory() > self.create_inputs() > self.create_commands() > self.gen_key() > > def _init_gpg_directory(self): > # Path to the gpg2 executable > self.gpg_path = "gpghome/gpg2" > > def create_inputs(self): > # Each stage of the key creation program takes one > # element from this list in order as a response. > inputs = [ > "11", > "Q", > "1", > "0", > "y", > self.username, > self.email, > "none", > "O", > ] > self.input_data = self.encode_input(inputs) > > def encode_input(self, user_input): > return ("\n".join(user_input) + "\n").encode() > > def create_commands(self): > # The commands and options passed to the terminal > self.commands = [ > self.gpg_path, > "--expert", > "--full-gen-key", > "--with-colons", > "--command-fd", > "0", > "--status-fd", > "1", > ] > > def gen_key(self, commands=None, user_input=None): > process = Process(target=self.type_passphrase) > process.start() > self.parse_output(self.commands, self.input_data) > > def type_passphrase(self): > # The pin-entry box wasn't accepting text from pynput. > # But sending newline characters worked for some reason. > # So, I just skipped password entry.... > key_presser = keyboard.Controller() > sleep(0.3) > for _ in range(4): > sleep(0.2) > key_presser.type("\n") > > def parse_output(self, commands, user_input): > self._output = subprocess.check_output( > commands, input=user_input > ) > try: > self.output_lines = self._output.split("\n") > except: > self.output_lines = self._output > self.key_id = self._output[-41:-1] > > @property > def output(self): > return self.output_lines > From asad.hasan2004 at gmail.com Mon Dec 2 08:55:29 2019 From: asad.hasan2004 at gmail.com (Asad) Date: Mon, 2 Dec 2019 19:25:29 +0530 Subject: [Tutor] How to Compare rpm version using Python Script In-Reply-To: <2a0d939f-9622-291d-5e74-87511ea70ca7@DancesWithMice.info> References: <1c8702ee-e30a-fd40-c0e3-2b87c34dfb40@wichmann.us> <20191130001632.zltebp32xhrr4zl5@apple.graniteweb.com> <2a0d939f-9622-291d-5e74-87511ea70ca7@DancesWithMice.info> Message-ID: Hi All , I am trying to use Json to serialize the data .I wrote a small code : run the command : rpm -qa --queryformat "%{NAME} %{VERSION} %{RELEASE} %{ARCH}\n" > /tmp/rpm.output It gives a list of rpm separated by space . How can I convert to json so that I can then make it a python dictionary object dictOne ? dictTwo is a required list of rpm's which is to be checked . for rpmOne in dictOne: for rpmTwo in dictTwo: if rpmOne["name"] == rpmTwo["name"]: if rpmOne["arch"] == "x86_64" : if rpmOne["version"] >= rpmTwo["version"] : #print rpm["name"],rpm["arch"],rpm["version"], "Installed" Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) else : #print rpm["name"],rpm["arch"],rpm["version"] , "Version is less than required" Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) elif rpm["arch"] == "i686" : if rpm["version"] >= rpmTwo["version"] : #print rpm["name"],rpm["arch"],rpm["version"], "Installed" Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) else : #print rpm["name"],rpm["arch"],rpm["version"] , "Version is less than required" Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) else: continue else : NotInstalledrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) for install in Installedrpm : print install[0],install[1],install[2] for noninstall in NotInstalledrpm: print noninstall Please advice if there could be simpler or smarter way to achieve this . On Sat, Nov 30, 2019 at 1:30 PM David L Neil via Tutor wrote: > On 30/11/19 3:07 PM, David wrote: > > On Sat, 30 Nov 2019 at 12:01, Alan Gauld via Tutor > wrote: > > > >> I used to work beside a data processing team who spent their lives > >> creating reports from old COBOL based systems. They used to write > >> their processed (ie pre-report) data extracts into CSV format files > >> but instead of commas they used the cedilla character(?), as it > >> was hardly ever found in real world data (at least not in our area, > >> maybe in Romance based language areas that might not hold good). > >> But the point was to use a character that you will not actually > >> find in the text as a separator. > > > > Years ago I noticed that ASCII contains several control characters that > > are specifically intended as data separators: > > https://en.wikipedia.org/wiki/Control_character#Data_structuring > > > > I sometimes use them in my shell scripting where appropriate, due to > > the limited data structures available there, but I've never seen them > used > > or advocated anywhere else. > > > > Are there reasons why they are not used more widely by programmers > > to solve simple textual data separation problems? > > > > I assume that they would still work with utf8, although I've not tested > > that. > > Many of the "control characters" had specific purposes, perhaps in > certain situations or in relation to particular devices, eg xOA is still > used as printer/screen/etc LineFeed to this day. So, need to be careful > in case the output is ever printed (for example). > > In ASCII there were official "separator" characters (x1C-1F), to which > users could assign their own particular meaning, even though they were > assigned names, eg "Record Separator". > > These (latter) have carried-through to UTF-8, eg "INFORMATION SEPARATOR > ONE" through "...FOUR", and seem quite appropriate to the OP's application. > > -- > Regards =dn > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Asad Hasan +91 9582111698 From alan.gauld at yahoo.co.uk Mon Dec 2 11:07:37 2019 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 2 Dec 2019 16:07:37 +0000 Subject: [Tutor] How to Compare rpm version using Python Script In-Reply-To: References: <1c8702ee-e30a-fd40-c0e3-2b87c34dfb40@wichmann.us> <20191130001632.zltebp32xhrr4zl5@apple.graniteweb.com> <2a0d939f-9622-291d-5e74-87511ea70ca7@DancesWithMice.info> Message-ID: <4fef065a-058c-74fe-09a3-f4bec998c086@yahoo.co.uk> On 02/12/2019 13:55, Asad wrote: > I am trying to use Json to serialize the data ... > It gives a list of rpm separated by space . How can I convert to json so > that I can then make it a python dictionary object dictOne ? I'm not sure why you think you need JSON? Can you not just save the space separated data into a text file and process that line by line? I'm not sure how JSON helps? You can then read the lines back and use line.split() to get the individual fields in a list. > dictTwo is a required list of rpm's which is to be checked . If it is a list why is it called a dict? It is always better to avoid putting types into variable names. Better to describe the variables purpose. > for rpmOne in dictOne: > for rpmTwo in dictTwo: > if rpmOne["name"] == rpmTwo["name"]: > if rpmOne["arch"] == "x86_64" : > if rpmOne["version"] >= rpmTwo["version"] : > #print rpm["name"],rpm["arch"],rpm["version"], "Installed" > Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) > else : > #print rpm["name"],rpm["arch"],rpm["version"] , "Version is > less than required" > Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) > elif rpm["arch"] == "i686" : > if rpm["version"] >= rpmTwo["version"] : > #print rpm["name"],rpm["arch"],rpm["version"], "Installed" > Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) > else : > #print rpm["name"],rpm["arch"],rpm["version"] , "Version is > less than required" > Installedrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) > else: > continue > else : > > NotInstalledrpm.append([rpm["name"],rpm["arch"],rpm["version"]]) This confuses the actual tests with the outcome actions. It is probably better to put the tests in a comparison function (or set of functions). Better still create a class from the line data and write some comparison operators as methods. Then you can do something like: rpm1 = RPM(file.readline().strip().split()) rpm2 = RPM(file.readline().strip().split()) if rpm1 > rpm2: # save one of them somewhere... elif rpm1 < rpm2 # deal with the opposite cae else: # deal with the equality case. > for install in Installedrpm : > print install[0],install[1],install[2] Would become for rpm in installed_rpms: print rpm # using the __str__ method of RPM class. > Please advice if there could be simpler or smarter way to achieve this . Probably not much simpler to code but a lot simpler to read the final logic -- 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 From basicbare at gmail.com Thu Dec 5 13:22:02 2019 From: basicbare at gmail.com (Alan Thwaits) Date: Thu, 5 Dec 2019 13:22:02 -0500 Subject: [Tutor] New Member Intro Message-ID: I'm brand-new to Python and to this list. In fact, I have no programming experience at all, save an introductory course in BASIC that I took in 1981. So far, I've installed Python 3.8.0 on my Windows 10 machine, have bookmarked a few online tutorials, and have requested a couple of "beginning Python" books from the local public library. And so the adventure begins. I expect I'll be asking some embarrassingly simple questions, just so I can get off the ground with this. Please be gentle. Thanks! Alan From mats at wichmann.us Thu Dec 5 17:36:01 2019 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 5 Dec 2019 15:36:01 -0700 Subject: [Tutor] New Member Intro In-Reply-To: References: Message-ID: On 12/5/19 11:22 AM, Alan Thwaits wrote: > I'm brand-new to Python and to this list. In fact, I have no programming > experience at all, save an introductory course in BASIC that I took in > 1981. > > So far, I've installed Python 3.8.0 on my Windows 10 machine, have > bookmarked a few online tutorials, and have requested a couple of > "beginning Python" books from the local public library. And so the > adventure begins. > > I expect I'll be asking some embarrassingly simple questions, just so I can > get off the ground with this. Please be gentle. welcome! simple is fine. just be sure to give enough information to help the list help you... think of if someone came to you with a question. People sometimes pop up with the python equivalent of "my car won't work, can you help" and then sadly the answer becomes No.... (grin) From PyTutor at DancesWithMice.info Thu Dec 5 20:02:48 2019 From: PyTutor at DancesWithMice.info (David L Neil) Date: Fri, 6 Dec 2019 14:02:48 +1300 Subject: [Tutor] New Member Intro In-Reply-To: References: Message-ID: <76ec5c5d-5d00-baac-cf71-32632e36780f@DancesWithMice.info> On 6/12/19 11:36 AM, Mats Wichmann wrote: > On 12/5/19 11:22 AM, Alan Thwaits wrote: >> I'm brand-new to Python and to this list. In fact, I have no programming >> experience at all, save an introductory course in BASIC that I took in >> 1981. >> >> So far, I've installed Python 3.8.0 on my Windows 10 machine, have >> bookmarked a few online tutorials, and have requested a couple of >> "beginning Python" books from the local public library. And so the >> adventure begins. >> >> I expect I'll be asking some embarrassingly simple questions, just so >> I can >> get off the ground with this. Please be gentle. > > welcome! +1 > simple is fine.? just be sure to give enough information to help the > list help you... think of if someone came to you with a question. People > sometimes pop up with the python equivalent of "my car won't work, can > you help" and then sadly the answer becomes No....? (grin) +1 It never hurts to explain 'the bit you understand' and then 'the bit you don't'; to encourage answers at 'the right level'. That's a long, long, time between programming exercises! I'm estimating that back-then you were using BASIC with single letter or letter&digit variableNMs on some predecessor to the IBM PC (?ZX-80, Spectrum, TRS-80, Apple ][...). That said, in many ways things haven't changed much, with expanding interest in IoT (the Internet of Things) causing renewed attention to single-board computers, eg Raspberry Pi. They're not (physically) much bigger than the 'computers' we were assembling and experimenting with, all those decades ago. (but are significantly more powerful!) Sounds like you've taken a sound approach to learning. Another avenue you might like to consider are MOOCs (Massively Open On-line Courses) from platforms such as Coursera and edX. There are also plenty of on-line courses offered by private-providers. -- Regards =dn From basicbare at gmail.com Fri Dec 6 13:19:23 2019 From: basicbare at gmail.com (Alan Thwaits) Date: Fri, 6 Dec 2019 13:19:23 -0500 Subject: [Tutor] New Member Intro In-Reply-To: <78bd613d-b9db-8321-02e9-93fdb83dbfa6@yahoo.co.uk> References: <78bd613d-b9db-8321-02e9-93fdb83dbfa6@yahoo.co.uk> Message-ID: I've noted 1) and 2), and will govern myself accordingly. As for 3), that's good to know. Thanks! Alan On Fri, Dec 6, 2019 at 9:48 AM Alan Gauld wrote: > On 06/12/2019 11:18, Alan Thwaits wrote: > > You've made good points. Thanks! > > A couple of other points I should have added... > > 1) always use reply-ALL or reply-List to respond to tutor mails, > otherwise your mail only goes to the person who sent it.(Unless > of course that's what you want!) > > 2) Never send attachments. The server strips them out for > security reasons. > > 3) I meant to mention that I'm the moderator/owner of the > list so any administrative type things you can send to me > directly. > > Have fun. > > -- > 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 > > From ruigracianoediogo at gmail.com Sat Dec 7 08:05:22 2019 From: ruigracianoediogo at gmail.com (Reborn0fDarkness) Date: Sat, 7 Dec 2019 13:05:22 +0000 Subject: [Tutor] Tuple/Dict Message-ID: Hi! i have a test where i have to ask the person a number, and then do his divisers, make them into an tuple, add the tuple into a dict and then show the dict, and im losing my mind, any help? From mats at wichmann.us Sat Dec 7 11:56:54 2019 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 7 Dec 2019 09:56:54 -0700 Subject: [Tutor] Tuple/Dict In-Reply-To: References: Message-ID: On 12/7/19 6:05 AM, Reborn0fDarkness wrote: > Hi! i have a test where i have to ask the person a number, and then do his > divisers, make them into an tuple, add the tuple into a dict and then show > the dict, and im losing my mind, any help? Do this in small pieces. Can you get any piece to work? What parts don't make sense? Show us a piece of code. "do his divisers" is not detailed enough for us to know what you're after (or at least include the description from the assignment?) From martin at linux-ip.net Sat Dec 7 11:39:45 2019 From: martin at linux-ip.net (Martin A. Brown) Date: Sat, 7 Dec 2019 08:39:45 -0800 Subject: [Tutor] Tuple/Dict In-Reply-To: References: Message-ID: Hello Reborn0fDarkness, You didn't actually show any code, so I'll mention that when you show code we can actually help you considerably more. You asked some very simple questions, so I have provided some pointers and very simple answers. You'll still need to assemble the remote-controlled car yourself. See below. >Hi! i have a test where i have to >ask the person a number Try the input() function: https://docs.python.org/3/library/functions.html#input You will need to convert the returned value to some sort of number. I'll assume an integer, but you decide what applies to your situation. Something like: num = int(input('type a number: ')) >and then do his divisers You'll need to supply a function that computes the divisors. divisors = your_function(num) Supposing that your_function() returns a list .... >make them into an tuple This is very easy, with the built in function tuple(): https://docs.python.org/3/library/functions.html#func-tuple tdivisors = tuple(divisors) >add the tuple into a dict You don't say what the key should be. But, I'd imagine it'll be the original number, so you can set up a loop or whatever to collect numbers until your monkey subject tires of entering numbers. result = dict result[num] = tdivisors >and then show the dict, You say "show the dict". There are so many ways to do this, that you have tremendous freedom of how to do that. If you want to control what the output looks like, then you probably will write some sort of output presentation function using the very powerful new Python string formatting capabilities: https://www.python.org/dev/peps/pep-3101/ If you just want something dead simple to produce output, here's (my favorite) data structure debugging and diagnostic tool, pprint: https://docs.python.org/3.8/library/pprint.html You can print the data structure with: import sys, pprint pprint.pprint(result, stream=sys.stdout) # -- or sys.stderr >and im losing my mind, any help? I'm afraid you'll have to show your work on that one. There is no Python module or function to help on that. Good luck, -Martin -- Martin A. Brown http://linux-ip.net/ From bob at ralexander.it Sat Dec 7 11:16:00 2019 From: bob at ralexander.it (Robert Alexander) Date: Sat, 7 Dec 2019 17:16:00 +0100 Subject: [Tutor] Not sure how to use external command within python code (3.6) Message-ID: I wish to use Ookla's SpeedTest CLI (https://www.speedtest.net/apps/cli?) (after trying other Python libraries I didn't like). I'd like to issue a "speedtest -f json" command from within a python script and parse the results.? I am currently stuck with the following code: process = subprocess.Popen(['/usr/local/bin/speedtest', '-f json'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() which only populates the stderr variable stating that? [error] Invalid output format specified: json Given on the command line that syntax is good. What am I doing wrong? Thank you very much PS End goal will be monitoring the results and when they fall under a given threshold send me an email, but that's the final goal. From alan.gauld at yahoo.co.uk Sat Dec 7 14:40:00 2019 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 7 Dec 2019 19:40:00 +0000 Subject: [Tutor] Tuple/Dict In-Reply-To: References: Message-ID: <7632308e-9f49-e971-2c9d-03cd9fd75408@yahoo.co.uk> On 07/12/2019 13:05, Reborn0fDarkness wrote: > Hi! i have a test where i have to ask the person a number, and then do his > divisers, make them into an tuple, add the tuple into a dict and then show > the dict, and im losing my mind, any help? Which parts are giving you problems? Show us your code. Show us any error messages. Show us a sample user session - what does the computer ask? - What does the user type? - What does the computer respond with? What does "do his divisers" mean? Find all of them? Just the primes? The biggest? Tell us your Python version and OS too. Without that kind of information we are only making wild guesses. And we won't do your "test" for you... -- 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 From alan.gauld at yahoo.co.uk Sat Dec 7 14:41:43 2019 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 7 Dec 2019 19:41:43 +0000 Subject: [Tutor] Not sure how to use external command within python code (3.6) In-Reply-To: References: Message-ID: <689a6f6f-a6c3-a0a9-1339-834620f36e3c@yahoo.co.uk> On 07/12/2019 16:16, Robert Alexander wrote: > process = subprocess.Popen(['/usr/local/bin/speedtest', '-f json'], Sorry I haven't looked at this closely but it might be better to pass the flag and value seperately: process = subprocess.Popen(['/usr/local/bin/speedtest', '-f', 'json'],... Just a thought, -- 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 From PyTutor at DancesWithMice.info Sat Dec 7 15:02:16 2019 From: PyTutor at DancesWithMice.info (David L Neil) Date: Sun, 8 Dec 2019 09:02:16 +1300 Subject: [Tutor] Not sure how to use external command within python code (3.6) In-Reply-To: <689a6f6f-a6c3-a0a9-1339-834620f36e3c@yahoo.co.uk> References: <689a6f6f-a6c3-a0a9-1339-834620f36e3c@yahoo.co.uk> Message-ID: <054885a2-5483-d5f3-8e4b-7619094fe886@DancesWithMice.info> On 8/12/19 8:41 AM, Alan Gauld via Tutor wrote: > On 07/12/2019 16:16, Robert Alexander wrote: > >> process = subprocess.Popen(['/usr/local/bin/speedtest', '-f json'], > > Sorry I haven't looked at this closely but it might be better to pass > the flag and value seperately: > > process = subprocess.Popen(['/usr/local/bin/speedtest', '-f', 'json'],... > > Just a thought, Similar thinking: when the complex/advanced case doesn't work, simplify! Recommend review of https://docs.python.org/3/library/subprocess.html (.run() eases life, in most cases) and use the Python REPL to experiment with the simplest access to Speedtest (and to 'see' what is happening at each step!), then to add the 'bells and whistles', eg formatted output, and only then, receiving same back into Python... -- Regards =dn From pytutor at danceswithmice.info Sun Dec 8 03:28:16 2019 From: pytutor at danceswithmice.info (David L Neil) Date: Sun, 8 Dec 2019 21:28:16 +1300 Subject: [Tutor] Not sure how to use external command within python code (3.6) In-Reply-To: References: <689a6f6f-a6c3-a0a9-1339-834620f36e3c@yahoo.co.uk> <054885a2-5483-d5f3-8e4b-7619094fe886@DancesWithMice.info> Message-ID: <29d006ee-3e24-8fdf-c916-1a1be7471aee@DancesWithMice.info> On 8/12/19 8:57 PM, Robert Alexander wrote: > Thank you David. Unfortunately, this list defaults Reply to the previous author, cf ReplyAll or reply only to the list. > To learn this very interesting language I run Python inside the Atom > editor with the Hydrogen package and have stop things so to have almost > a ?Jupiter notebook? environment. Sounds good. I don't use either of those. Do they allow/enable the execution of a single statement, eg a single 'cell' within a Jupiter Notebook? > I also installed a linter and try to conform the code to PEP8 standards. > Sometimes it drives me crazy but teaches a lot :) There's quite a choir singing that song! Remember though, PEP-8 is specifically for PSL contributions (although it is useful within the wider community), also recall what the 'Zen of Python' says about "hobgoblins". It is probably (close to) heresy, but if you are investing a lot of energy into learning Python, perhaps some of these other things fall into the category of 'nice to have' - until you're reading for added challenges? > Your reference to REPL implies running interactively in ?line mode? to > execute, inspect results etc right? Correct. You may be able to do this with the aforementioned tools - I don't know. Some people use a debugger - but once again, it's more to learn before you even leave the starting-line. So, I'd recommend the most basic tool that comes with/as Python: running "python3" from the cmdLN. WebRefs: https://pythonprogramminglanguage.com/repl/ https://codewith.mu/en/tutorials/1.0/repl -- Regards =dn From rmlibre at riseup.net Tue Dec 10 09:14:08 2019 From: rmlibre at riseup.net (rmlibre at riseup.net) Date: Tue, 10 Dec 2019 06:14:08 -0800 Subject: [Tutor] GPG password entry automation help In-Reply-To: References: Message-ID: No one responded to the request I put out, so I ducked into the codebase of some other projects that also talk with GPG to learn their tricks. It was rough trying to find exactly what I was missing. But after narrowing down the possibilities and cross-referencing with the GPG documentation, I got it!! It's a big lesson for me in how to find answers: read the docs, other people's code, and other people's questions. I'll post the working code below. folder/ ----tiny_gnupg.py ----gpghome/ --------gpg2 ># tiny_gnupg.py > >from pathlib import Path >from subprocess import check_output > > >class GnuPG: > def __init__(self, username="", email="", passphrase=""): > self.set_homedir() > self.email = email > self.username = username > self.passphrase = passphrase > self.fingerprint = "" > > def set_homedir(self, path="gpghome"): > self.home = self.format_homedir(path) > self.executable = self.home + "/gpg2" > > def format_homedir(self, path="gpghome"): > return Path(path).absolute().as_uri().replace("file://", "") > > def encode_inputs(self, *inputs): > return ("\n".join(inputs) + "\n").encode() > > def read_output(self, command=None, inputs=b"", shell=False): > return check_output(command, input=inputs, shell=shell).decode() > > def gen_key(self): > command = [ > self.executable, # path to gpg2 executable > "--homedir", # this creates a non-system keyring > self.home, # path to keyring storage folder > "--pinentry-mode", # dunno exactly what this does, but it works > "loopback", > "--expert", > "--full-gen-key", > "--with-colons", > "--command-fd", > "0", > "--status-fd", > "1", > "--passphrase-fd", # tells GPG to expect the pw as the first input > "0", > ] > inputs = self.encode_inputs( > self.passphrase, > "9", > "1", > "0", > "y", > self.username, > self.email, > "There's safety in numbers.", > "O", > ) > output = self.read_output(command, inputs) > self.fingerprint = output.strip().split("\n")[-1][-40:] > > >username = "username" >email = "username at user.net" >passphrase = "test_user_passphrase" >gpg = GnuPG(username, email, passphrase) > ># This will generate a new combined encryption ed25519 ECC key and ># signing/certifying ed25519 ECC key. >gpg.gen_key() This was really difficult to figure out, and from searching the web, lot's of folks have trouble figuring out the GPG interface. I turned my solution into a package with the other encrypt, decrypt, keyserver upload and download functions coded as well, for anyone who stumbles across this problem in the future: https://pypi.org/project/tiny-gnupg/. It's all gplv3 licensed. Also, thanks, Joe, for the initial insight and guidance for me to find the right direction to explore! :) From d_e_white at icloud.com Wed Dec 11 13:09:20 2019 From: d_e_white at icloud.com (Dan White) Date: Wed, 11 Dec 2019 18:09:20 -0000 Subject: [Tutor] A venv question - multi-user ? Message-ID: <32e8b844-9fcf-448c-8533-3f7a0896e3e0@me.com> Is there such a thing as a multi-user virtual environment ? All the instructions create a local file tree that belongs to the user that created it. ------------------------------------------------ ?Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.?? (Bill Waterson: Calvin & Hobbes) From joel.goldstick at gmail.com Thu Dec 12 10:19:47 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 12 Dec 2019 10:19:47 -0500 Subject: [Tutor] A venv question - multi-user ? In-Reply-To: <32e8b844-9fcf-448c-8533-3f7a0896e3e0@me.com> References: <32e8b844-9fcf-448c-8533-3f7a0896e3e0@me.com> Message-ID: Is that a good idea? Or better to pull code from git? On Wed, Dec 11, 2019, 6:40 PM Dan White via Tutor wrote: > Is there such a thing as a multi-user virtual environment ? > All the instructions create a local file tree that belongs to the user > that created it. > ------------------------------------------------ > ?Sometimes I think the surest sign that intelligent life exists elsewhere > in the universe is that none of it has tried to contact us.? (Bill > Waterson: Calvin & Hobbes) > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > From mats at wichmann.us Thu Dec 12 10:57:38 2019 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 12 Dec 2019 08:57:38 -0700 Subject: [Tutor] A venv question - multi-user ? In-Reply-To: <32e8b844-9fcf-448c-8533-3f7a0896e3e0@me.com> References: <32e8b844-9fcf-448c-8533-3f7a0896e3e0@me.com> Message-ID: <39c422bf-1251-4a80-ea05-cff87bcf8b63@wichmann.us> On 12/11/19 11:09 AM, Dan White via Tutor wrote: > Is there such a thing as a multi-user virtual environment ? > All the instructions create a local file tree that belongs to the user > that created it. There's nothing to prevent it. Put it in location that is not user specific (on linux you could use something like /usr/local/share), and make sure it's readable by the group the users are in. The mechanism itself doesn't care, you just find where it's installed and run the activate script appropriate to the shell you're using, and you're good to go. But the idea of a virtualenv is to isolate a specific bit of work, so this may not be a really great idea - what if some other user installs packages via pip that you didn't want, or changes the version of such packages, etc. From pas.celia at live.be Fri Dec 13 13:00:17 2019 From: pas.celia at live.be (celia pas) Date: Fri, 13 Dec 2019 18:00:17 +0000 Subject: [Tutor] Problem python In-Reply-To: References: , Message-ID: Dear, I have encountered a problem where there is no solution for on the internet. The question is involving the Bio.Align.PairwiseAligner() function. You can find my script and fasta sequence in the appendix. I try to run this program using the sequence when I got the following error: [cid:image001.png at 01D5B1E2.C2F2E080] I am 100% sure there is NO letter in the sequence that is not in the alphabet, as you will see the program will probably work perfectly fine on your computer. Even weirder is that I didn?t have this problem this morning with the exact same script and sequence so something else must be wrong. I have tried to do the following things to fix the problem: -reinstall the biopython package -reinstall python and pycharm completely from scratch -turned my pc on and off again multiple times -deleted non-relevant packages I have downloaded earlier today such as the blast+ and clustalx package that might have had an influence I am really out of solutions and I am really desperate as this is my new laptop (only have it for a week) so I want to make sure there is nothing wrong with my laptop itself, or if there is that I can fix it. Furthermore this script is essential for my PhD research. You are my last resort so I would be incredibly greatful if you?d be able to help me. Thanks in advance for your time. Kind regards, C?lia Sent from Mail for Windows 10 -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pythonscript.txt URL: From zimmerman.k at icloud.com Fri Dec 13 13:43:20 2019 From: zimmerman.k at icloud.com (Kelvin Zimmerman) Date: Fri, 13 Dec 2019 13:43:20 -0500 Subject: [Tutor] Pymongo | Python 3.7 | MongoDb Community : write scrape results to db Message-ID: <27A45F5E-4A69-49B9-B5CD-DC3A1DF19530@icloud.com> Hi, Let me start by saying I am very new to both python and mongo. I am just and hobbyist so my issue maybe basic to most but never less, I am thankful for any help, guidance, as I am stuck! Objective: Im using to run a craigslist jobs search for multi-locations and then attempt to both print the results to the screen and into the db. I am able to connect to the db without issue, I think my issue is in creating the dict .bson ?? piece to this puzzle. Please see below: from craigslist import CraigslistJobs # database import pymongo from pymongo import MongoClient from unicodedata import name from _datetime import datetime from scrapy.utils import url try: client = MongoClient() print("Connected Successfully!") except: print("Could Not Connect !") # dbase client client = MongoClient() client = MongoClient('localhost', 27017) # dbase db = client['craigslistResults'] # write to database mydict = {'name': name.get_text(), 'url': url.get_text(), 'datetime': datetime.get_text(), 'price': price.get_text() } x = db.craigslistResultsFreelance.insert_many(mydict) abilene = CraigslistJobs(site='abilene', category='jjj', filters={'is_telecommuting': True}) for abileneResult in abilene.get_results(): print(abileneResult) sfbay = CraigslistJobs(site='sfbay', category='jjj', filters={'is_telecommuting': True}) for sfbayResult in sfbay.get_results(): print(sfbayResult) newyork = CraigslistJobs(site='newyork', category='jjj', filters={'is_telecommuting': True}) for newyorkResult in newyork.get_results(): print(newyorkResult) Any insight is greatly appreciated! From alan.gauld at yahoo.co.uk Sat Dec 14 11:30:14 2019 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 14 Dec 2019 16:30:14 +0000 Subject: [Tutor] Problem python In-Reply-To: References: Message-ID: <27cb9f64-1474-0e37-f091-adce95f96ba3@yahoo.co.uk> On 13/12/2019 18:00, celia pas wrote: > ... The question is involving the Bio.Align.PairwiseAligner() function. The python tutor list is really for questions about the Python language and its core standard library. The Bio package is not part of that so questions are more likely to get an answer on the Bio mailing list: biopython at biopython.org Where the readers will all be familiar with the library in question. -- 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 From alan.gauld at yahoo.co.uk Sat Dec 14 11:35:00 2019 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 14 Dec 2019 16:35:00 +0000 Subject: [Tutor] Pymongo | Python 3.7 | MongoDb Community : write scrape results to db In-Reply-To: <27A45F5E-4A69-49B9-B5CD-DC3A1DF19530@icloud.com> References: <27A45F5E-4A69-49B9-B5CD-DC3A1DF19530@icloud.com> Message-ID: <9702558c-37e5-89f2-9d58-b77ca6da5f1a@yahoo.co.uk> On 13/12/2019 18:43, Kelvin Zimmerman via Tutor wrote: > Let me start by saying I am very new to both python and mongo. Hi, the Python tutor list is really for questions about the core python language and its standard library (as well as general programming topics). PyMongo is not one of those packages so you are more likely to get an answer on a dedicated Mongo mailing list/forum. There are several options described here: http://www.mongodb.org/about/support But there may be a few Mongo users on this list and you will get lucky. If not try again on one of the links referenced above. -- 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 From akleider at sonic.net Sun Dec 15 18:47:29 2019 From: akleider at sonic.net (Alex Kleider) Date: Sun, 15 Dec 2019 15:47:29 -0800 Subject: [Tutor] Pymongo | Python 3.7 | MongoDb Community : write scrape results to db In-Reply-To: <27A45F5E-4A69-49B9-B5CD-DC3A1DF19530@icloud.com> References: <27A45F5E-4A69-49B9-B5CD-DC3A1DF19530@icloud.com> Message-ID: <9ebd68fb2cd542351227f0dfa1e5eedf@sonic.net> On 2019-12-13 10:43, Kelvin Zimmerman via Tutor wrote: > Hi, > > Let me start by saying I am very new to both python and mongo. I am > just and hobbyist so my issue maybe basic to most but never less, I am > thankful for any help, guidance, as I am stuck! > > Objective: Im using to run a craigslist jobs search for > multi-locations and then attempt to both print the results to the > screen and into the db. I am able to connect to the db without issue, > I think my issue is in creating the dict .bson ?? piece to this > puzzle. I don't have many of the non standard library modules that you are using so I commented out a lot of stuff just to get to what I believe is the first problem: from _datetime import datetime from unicodedata import name #import pymongo #from craigslist import CraigslistJobs #from pymongo import MongoClient #from scrapy.utils import url # database #try: #client = MongoClient() #print("Connected Successfully!") #except: #print("Could Not Connect !") # dbase client #client = MongoClient() #client = MongoClient('localhost', 27017) # dbase #db = client['craigslistResults'] # write to database mydict = {'name': name.get_text(), #'url': url.get_text(), 'datetime': datetime.get_text(), 'price': price.get_text() } and here's the traceback I got: python tutor.py Traceback (most recent call last): File "tutor.py", line 20, in mydict = {'name': name.get_text(), AttributeError: 'builtin_function_or_method' object has no attribute 'get_text' It surprises me that the error reported wasn't NameError: name 'name' is not defined I suggest you send the Traceback you are getting to the list. From akleider at sonic.net Sun Dec 15 18:55:24 2019 From: akleider at sonic.net (Alex Kleider) Date: Sun, 15 Dec 2019 15:55:24 -0800 Subject: [Tutor] Pymongo | Python 3.7 | MongoDb Community : write scrape results to db In-Reply-To: <9ebd68fb2cd542351227f0dfa1e5eedf@sonic.net> References: <27A45F5E-4A69-49B9-B5CD-DC3A1DF19530@icloud.com> <9ebd68fb2cd542351227f0dfa1e5eedf@sonic.net> Message-ID: <2323fd83f49bad9d3f986186b3ffc736@sonic.net> On 2019-12-15 15:47, Alex Kleider wrote: > It surprises me that the error reported wasn't > NameError: name 'name' is not defined > I shouldn't have been surprised: you've imported it from unicodedata! From Richard at Damon-Family.org Sun Dec 15 19:00:07 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 15 Dec 2019 19:00:07 -0500 Subject: [Tutor] Pymongo | Python 3.7 | MongoDb Community : write scrape results to db In-Reply-To: <9ebd68fb2cd542351227f0dfa1e5eedf@sonic.net> References: <27A45F5E-4A69-49B9-B5CD-DC3A1DF19530@icloud.com> <9ebd68fb2cd542351227f0dfa1e5eedf@sonic.net> Message-ID: <6c3ab2c2-4ff6-d8e0-04cc-72eb01e4bae3@Damon-Family.org> On 12/15/19 6:47 PM, Alex Kleider wrote: > On 2019-12-13 10:43, Kelvin Zimmerman via Tutor wrote: >> Hi, >> >> Let me start by saying I am very new to both python and mongo.? I am >> just and hobbyist so my issue maybe basic to most but never less, I am >> thankful for any help, guidance, as I am stuck! >> >> Objective:? Im using to run a craigslist jobs search for >> multi-locations and then attempt to both print the results to the >> screen and into the db.? I am able to connect to the db without issue, >> I think my issue is in creating the dict .bson ?? piece to this >> puzzle. > > I don't have many of the non standard library modules that you are > using so I commented out a lot of stuff just to get to what I believe > is the first problem: > > from _datetime import datetime > from unicodedata import name > #import pymongo > #from craigslist import CraigslistJobs > #from pymongo import MongoClient > #from scrapy.utils import url > # database > #try: > ??? #client = MongoClient() > ??? #print("Connected Successfully!") > #except: > ??? #print("Could Not Connect !") > # dbase client > #client = MongoClient() > #client = MongoClient('localhost', 27017) > # dbase > #db = client['craigslistResults'] > # write to database > mydict = {'name': name.get_text(), > ????????? #'url': url.get_text(), > ????????? 'datetime': datetime.get_text(), > ????????? 'price': price.get_text() > ????????? } > > and here's the traceback I got: > python tutor.py > Traceback (most recent call last): > ? File "tutor.py", line 20, in > ??? mydict = {'name': name.get_text(), > AttributeError: 'builtin_function_or_method' object has no attribute > 'get_text' > > It surprises me that the error reported wasn't > NameError: name 'name' is not defined > > > I suggest you send the Traceback you are getting to the list. > This gets a binding for name: from unicodedata import name But that name is a method, and it doesn't have an attribute get_text. I suspect something else is wanted here. -- Richard Damon From motka22 at gmail.com Tue Dec 17 18:55:07 2019 From: motka22 at gmail.com (Motka Blank) Date: Tue, 17 Dec 2019 15:55:07 -0800 Subject: [Tutor] Help : Response Headers Location Message-ID: Hello all, I am testing implicit grant flow, directly call to example: oauthurl = https://xxx.com? response_type=token&response_uri= http://127.0.0.1:5000/&client_id=tester-grants If I put above url in browser, it goes to login page and I put username, password and submit the form, next page ( redirect uri) showed up with access_token http://127.0.0.1:5000/#access_token=abcdxyz Question: How can I get this access_token from backend python code.? ( I cannot use front end code, just use backend). I have tried several stuff and I did not get success yet. (1) I tried selenium webdriver: driver = webdriver.PhantomJS(executable_path='/usr/local/bin/phantomjs' ) driver.get(oauthurl) username_field = driver.find_element_by_name('pf.username') username_field.send_keys(username) password_field = driver.find_element_by_name('pf.pass') password_field.send_keys(password) submit_button = driver.find_element_by_id('login-button') submit_button.submit() time.sleep(20) current_url = driver.current_url is showing oauthurl and it did not change. I want to get redirect_uri with #access_token. If I get url including access_token, I can split access_tikne from url. But now I could not get this redirect url and I am struck with this. Please help me what python library I should use or sample of code that can get redirect uri would be very helpful. When I got http://127.0.01:5000/#access_token=abcdxyz, in inspect, network - I saw the access_token as a part of response headers Location. Please share me if you have that kind of experience. I have been working on that for a week now. Thanks in advance, Motka From hamnahxbaig at gmail.com Wed Dec 18 05:40:33 2019 From: hamnahxbaig at gmail.com (Hamnah Baig) Date: Wed, 18 Dec 2019 10:40:33 +0000 Subject: [Tutor] Hi there! Message-ID: Can you help me with this code? I'm struggling to create a leaderboard/score system and a login system along with an exit option that exits and goes back to the start. code : # import varibles import time #Used to lock import random #Used for dice import sys #Used to exit from random import randint #Varibles p1totaltotal = 0 p2totaltotal = 0 #opt = " " #scoreboards = 0 tries = 1 enter = 0 rounds = 0 #]p1 = 0 #p2 = 0 #p1roll3 = 0 #p2roll3 = 0 even = [2, 4, 6, 8, 10, 12, 14, 16, 18] odd = [3, 5, 7, 9, 11, 13, 15, 17] #no = 0 #rolls = 1 #Droll = 1 p1go = 0 p2go = 0 rolling = 0 #rollin = 0 #dice = 0 # Authorization (Password login) while enter == 0: password =input('Please enter the authorization password:') if password == "321": print ('\n') print('Authorization password is correct, Welcome to the Dice Game.') rolls = 0 enter = 1 + enter elif tries == 3: print('Ops, you have entered the authorization password wrong too many times.') print('You have been locked out for 10 minutes') time.sleep(600) tries = 0 else: print('\nThis is an incorrect password please try again or ask the help desk') tries = 1 + tries # This is how to enter the players Usernames print ('\n') true = input("please press '!' to enter the players usernames?") if true == "!": print('This is a 2 player game, so can the players please enter their usernames.') pname1 = input ('\nWhat would player one liked to be called?') pname2 = input ('\nWhat would player two liked to be called?') print('welcome', pname1, ',and welcome', pname2, ',to the two player dice game') # This it how to can select an option print ('\n') opt = input("please type 'open' to look at the options?") if opt == "open": print("please select an option.") print("1: Enter the game") print("2: Rules") print("3: Exit") opt=input('What would you like to do, please select a number:') else: print('please can you type open') while int(opt) < 1 or int(opt) > 4: print('That is not a valid option.') print('Please enter a number between 1 and 4:') opt=input() #This is the game rules if opt == 2: print('\nRules') print('\nThe dice game is a very simple game to understand:') print('\nTwo players take turns to roll two dices.') print("\nThey both roll the dice twice over 5 rounds") print("\nthe way to win is who ever has the highest even number will win") print("\nIf both players have the same score at the end of the 5 rounds, they will each roll one more dice and whoever has the highest score will be the winner") #this is how you exit the game print ('\n') if opt == 3: print('now exiting the game') sys.exit() #This is the game code if opt == 1: time.sleep(0.3) print("Hello player!") while rounds < 5: print("Round ",rounds + 1) p1 = input("\nPlayer 1 press r to roll") if p1 == "r": p1roll1 = random.randint(1, 6) p1roll2 = random.randint(1, 6) p1roll3 = p1roll1 + p1roll2 print("Dice 1 rolled a", p1roll1, ".") print("Dice 2 rolled a", p1roll2, ".") print("Player 1 your roll was a", p1roll3, ".") else: print("\nTo play the game could you please press 'r'") if p1roll1 == p1roll2: print("You got a double. You get one more roll.") double = random.randint(1, 6) p1roll3 = p1roll3 + double print("The double dice rolled a", double, ".") print("You got", p1roll3, ".") #Rolls an odd if p1roll3 % 2 ==0: p1roll3 = p1roll3 + 10 else: p1roll3 = p1roll3 - 5 if p1roll3 <0: p1roll3 = 0 print("You rolled a odd number 5 points have been removed from your score. You now have",p1roll3, "points.") p1totaltotal = p1totaltotal + p1roll3 p2 = input("\nPlayer 2 press r to roll") if p2 == "r": p2roll1 = random.randint(1, 6) p2roll2 = random.randint(1, 6) p2roll3 = p2roll1 + p2roll2 print("Dice 1 rolled a", p2roll1, ".") print("Dice 2 rolled a", p2roll2, ".") print("Player 2 your roll was a", p2roll3, ".") else: print("\nTo play the game could you please press 'r'") if p2roll1 == p2roll2: print("You got a double. You get one more roll.") double = random.randint(1, 6) p2roll3 = p1roll3 + double print("The double dice rolled a", double, ".") print("You got", p2roll3, ".") #Rolls an odd if p2roll3 % 2 ==0: p2roll3 = p2roll3 + 10 else: p2roll3 = p2roll3 - 5 if p2roll3 <0: p2roll3 = 0 print("You rolled a odd number 5 points have been removed from your score. You now have",p2roll3, "points.") p2totaltotal = p2totaltotal + p2roll3 rounds = rounds + 1 #Final Scores print("\nThe scores have been added up and") time.sleep(2) print('\n') print(pname1 , "got", p1go, ".") print(pname2 , "got", p2go, ".") From mats at wichmann.us Wed Dec 18 09:40:45 2019 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 18 Dec 2019 07:40:45 -0700 Subject: [Tutor] Hi there! In-Reply-To: References: Message-ID: <548848b5-b9d1-0bf5-48c0-900217a453a5@wichmann.us> On 12/18/19 3:40 AM, Hamnah Baig wrote: > Can you help me with this code? > I'm struggling to create a leaderboard/score system and a login system > along with an exit option that exits and goes back to the start. just a couple of quick notes, I'm sure you'll get some others. 1. what's the problem? something is causing you to ask for help - if there are errors, or unexpected behavior, please describe it. 2. your code runs on, and on, and on... it would be much more readable if split into functions that do distinct things. Have you by any chance not gotten to learning about functions yet? 2b. in particular, one chunk of code is repeated exactly, with just variable names changed (the rolling for each user), that should be a hint to you that you should refactor that to use a function. 3. you define some stuff you don't use... like the even and odd arrays. I see you've appropriately computed even/odd through a modulus operation and so you don't need these declarations. You have a lot of other things that look like you thought you needed then, then you commented them out. Now they're just clutter. 4. at the very end you try to print totals, but you have never used these variables: > p1go = 0 > p2go = 0 ... > #Final Scores > > print("\nThe scores have been added up and") > time.sleep(2) > print('\n') > print(pname1 , "got", p1go, ".") > print(pname2 , "got", p2go, ".") you are collecting the totals as you go into differently named things, so you should use those... BUT: 5. your instructions imply that you're looking for a high roll. print('\nRules') print('\nThe dice game is a very simple game to understand:') print('\nTwo players take turns to roll two dices.') print("\nThey both roll the dice twice over 5 rounds") print("\nthe way to win is who ever has the highest even number you're not doing anything with this... you seem to add 10 if the roll is even (and subtract 5 if odd), but then instead you're summing the rolls, not recording a high roll. Is this intended? Where do the +10 and -5 come from? If that's not obvious (it isn't to me), then there should have been a comment explaining what that was for. 6. you suggest that options 1 to 4 are valid, but do nothing with a value of 4 while int(opt) < 1 or int(opt) > 4: print('That is not a valid option.') print('Please enter a number between 1 and 4:') A lot of the problems are the result of hacking: you started writing, and then you changed things, and then you changed things. A better way to attack such a problem is in small chunks. You "decompose" the problem into small bits of functionalty, code just that piece, and test it, substituting hardcoded or otherwise "mocked" values where those would have needed stuff from the rest of the program you haven't written yet. Then build it up, making sure each new piece doesn't break the pieces you already wrote and tested. From bruno.cramer at gmail.com Thu Dec 19 11:28:56 2019 From: bruno.cramer at gmail.com (Bruno Cramer) Date: Thu, 19 Dec 2019 13:28:56 -0300 Subject: [Tutor] Python scripts-MAWS and JAWS Message-ID: Dear python programmers, I am a university researcher (retired but still contributing) using computational chemistry as main tool. I am trying to develop with other colleague a biosensor with aptamers for neglected infectious diseases as Leishmaniasis. In year 2015 iGEM Heidelberg team developed an aptamer design tool called MAWS written in Python. In my opinion an excellent tool, if put to work. I tried to run the program for several weeks without success. As it uses AMBER software as platform, I also updated the M.A.W.S script with the corresponding force fields, etc. However, the program keeps showing error when running. I am new to Python programming and I could not find out what to do. I would be very grateful if somebody can make this program run without error. NOTE; I tried to contact the developers, also when I was in Germany this year I tried to find them. No way, and no e-mail feed back. Link to program MAWS and JAWS download. http://2015.igem.org/Team:Heidelberg/software/maws click on Software and download MAWS and JAWS.Under 'Results' you'll find the link to Github repository. Thank you for your support. Bruno From alan.gauld at yahoo.co.uk Thu Dec 19 12:38:36 2019 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 19 Dec 2019 17:38:36 +0000 Subject: [Tutor] Python scripts-MAWS and JAWS In-Reply-To: References: Message-ID: On 19/12/2019 16:28, Bruno Cramer wrote: > In year 2015 iGEM Heidelberg team developed an aptamer design tool called > MAWS written in Python. In my opinion an excellent tool, if put to work. > > I tried to run the program for several weeks without success. As it uses > AMBER software as platform, I also updated the M.A.W.S script with the > corresponding force fields, etc. > However, the program keeps showing error when running. OK, First I have to point out that this list is for those studying the core language and its standard library, so this isa bit off topic and you are not likely to find many users of gis software here. You might find some users on the SciPy mailing list, failing that you could try the main Python mailing list, where the Python guru's hang out. But before trying either you need some extra information. Python version, OS, and the actual error trace - all of it - to paste into your message. Don;t expect anyone to download and run an application - that may be of no use to them! - just to answer your question. You will need to generate the errors. If you need to feed it data then a few lines of sample data will help too. Plus any corresponding data output - ideally the actual output for the provided sample input.. > Link to program MAWS and JAWS download. > http://2015.igem.org/Team:Heidelberg/software/maws Clicking on the Team->Attributions link takes me to a page of links to contact details. That might get you someone who can help... -- 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 From mats at wichmann.us Thu Dec 19 13:27:35 2019 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 19 Dec 2019 11:27:35 -0700 Subject: [Tutor] Python scripts-MAWS and JAWS In-Reply-To: References: Message-ID: On 12/19/19 9:28 AM, Bruno Cramer wrote: piling on to Alan's comment: > I tried to run the program for several weeks without success. As it uses > AMBER software as platform, I also updated the M.A.W.S script with the > corresponding force fields, etc. > However, the program keeps showing error when running. > I am new to Python programming and I could not find out what to do. Step 1 would be to tell people what the error is. Otherwise it's like your car... "the Check Engine light is on, what can I do to fix it?" - somebody needs to know what error it's actually reporting to even respond. (in the case of cars, you need one of those readers to be able to extract the code, Python usually prints it out for you, unless it's someone hid it behind a GUI) even if we don't know the software, the precise error message might give some hints.... From mats at wichmann.us Thu Dec 19 15:17:37 2019 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 19 Dec 2019 13:17:37 -0700 Subject: [Tutor] Help : Response Headers Location In-Reply-To: References: Message-ID: <09d49d6e-eb93-2e97-741c-df93b3d06076@wichmann.us> On 12/17/19 4:55 PM, Motka Blank wrote: > Hello all, > I am testing implicit grant flow, directly call to > example: > oauthurl = https://xxx.com? response_type=token&response_uri= > http://127.0.0.1:5000/&client_id=tester-grants > > If I put above url in browser, it goes to login page and I put username, > password and submit the form, next page ( redirect uri) showed up with > access_token > > http://127.0.0.1:5000/#access_token=abcdxyz > > Question: > How can I get this access_token from backend python code.? > ( I cannot use front end code, just use backend). > I have tried several stuff and I did not get success yet. > (1) I tried selenium webdriver: > > driver = webdriver.PhantomJS(executable_path='/usr/local/bin/phantomjs' > ) > driver.get(oauthurl) > username_field = driver.find_element_by_name('pf.username') > username_field.send_keys(username) > password_field = driver.find_element_by_name('pf.pass') > password_field.send_keys(password) > > submit_button = driver.find_element_by_id('login-button') > submit_button.submit() > time.sleep(20) > current_url = driver.current_url is showing oauthurl and it did not change. > I want to get redirect_uri with #access_token. If I get url including > access_token, I can split access_tikne from url. > But now I could not get this redirect url and I am struck with this. > Please help me what python library I should use or sample of code that can > get redirect uri would be very helpful. > When I got http://127.0.01:5000/#access_token=abcdxyz, in inspect, network - > I saw the access_token as a part of response headers Location. > Please share me if you have that kind of experience. I have been working on > that for a week now. your question doesn't make any sense. obtaining an access token which can then be passed on to a service provider is essentially a client operation. what do you mean by "how can I get this from backend python code"? From 7of9 at little-beak.com Fri Dec 20 07:01:51 2019 From: 7of9 at little-beak.com (Seven of Nine) Date: Fri, 20 Dec 2019 13:01:51 +0100 Subject: [Tutor] MacOS many copies of python Message-ID: <6936d3ac-3bb1-9907-ece4-b6b2a2d8bed0@little-beak.com> Hello, I have MacOS Catalina, and have many copies of python installed, trying to get pygame to work. Which is complicated by the fact that it only works on 32-bit version of 2.7, which I installed (via pip) but apparently i have some other version as my "base" install. Going into the python: I import sys, then print sys.path - and get the following ['', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] That doesn't look right? or clean to me? Can anyone lend a helping hand how I could sort my python version. From mats at wichmann.us Fri Dec 20 10:39:47 2019 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 20 Dec 2019 08:39:47 -0700 Subject: [Tutor] MacOS many copies of python In-Reply-To: <6936d3ac-3bb1-9907-ece4-b6b2a2d8bed0@little-beak.com> References: <6936d3ac-3bb1-9907-ece4-b6b2a2d8bed0@little-beak.com> Message-ID: <33fed809-6eca-0eb0-3324-ed88efd75b0b@wichmann.us> On 12/20/19 5:01 AM, Seven of Nine via Tutor wrote: > Hello, > > I have MacOS Catalina, and have many copies of python installed, trying > to get pygame to work. Which is complicated by the fact that it only > works on 32-bit version of 2.7, which I installed (via pip) but > apparently i have some other version as my "base" install. > > Going into the python: I import sys, then print sys.path - and get the > following > > ['', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', > '/usr/local/Cellar/python at 2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', > '/usr/local/lib/python2.7/site-packages'] > > > That doesn't look right? or clean to me? no, that looks fine. For any given Python version there will typically be many places that need to be searched for pieces that are relevant to using it. That's all just one version. you should probably try Python 3.7 (pygame binaries for the mac are not up yet for 3.8), 2.7 is effectively unsupported (officially unsupported as of Jan 1). You can see what pygame bundles are available here for pip to find: https://pypi.org/project/pygame/#files From mi8k0mi at gmail.com Mon Dec 23 04:27:35 2019 From: mi8k0mi at gmail.com (Aleksa) Date: Mon, 23 Dec 2019 10:27:35 +0100 Subject: [Tutor] stalker-m3u.py Message-ID: Error: Please upgrade your API plan to use filters or paging. NOT WORK..... Is there another way Thanks.. #!/usr/bin/env python # # stalker-m3u.py # Search SHODAN for Stalker Portal IPTV Servers M3U # # Author: random_robbie import shodan import sys import re import requests from time import sleep from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # Configuration API_KEY = "oCBoOofRgFReGU2ssMyp9Htqrfhgqlpf" SEARCH_FOR = 'title:"stalker_portal"' FILE = "/stalker_portal/server/tools/m3u.php" session = requests.Session() def grab_file (IP,PORT,FILE): print ("[*] Testing: "+IP+" on Port: "+PORT+"[*]\n") try: URL = "http://"+IP+":"+PORT+""+FILE+"" headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0"} response = session.get(URL, headers=headers, timeout=15, verify=False) result = response.text if '#EXTM3U' in result: text_file = open("./cfg/stalker-"+IP+".m3u8", "a") text_file.write(""+result+"") text_file.close() print ("[*] Stalker... Found [*]\n") else: print ("[*] Blocked [*]\n ") except KeyboardInterrupt: print ("Ctrl-c pressed ...") sys.exit(1) except Exception as e: print (e) print ("[*] Nothing Found on IP: "+IP+" [*]\n") try: # Setup the api api = shodan.Shodan(API_KEY) # Perform the search result = api.search(SEARCH_FOR) # Loop through the matches and print each IP for service in result['matches']: IP = service['ip_str'] PORT = str(service['port']) CC = service['location']['country_name'] grab_file (IP,PORT,FILE) except KeyboardInterrupt: print ("Ctrl-c pressed ...") sys.exit(1) except Exception as e: print('Error: %s' % e) sys.exit(1) From alan.gauld at yahoo.co.uk Mon Dec 23 07:13:42 2019 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 23 Dec 2019 12:13:42 +0000 Subject: [Tutor] Fwd: Re: stalker-m3u.py In-Reply-To: <05a307ee-d835-48ef-9ff0-95a062b89956@btinternet.com> References: <05a307ee-d835-48ef-9ff0-95a062b89956@btinternet.com> Message-ID: <7911d533-b931-4749-eb6b-77e8e12aaedb@yahoo.co.uk> On 23/12/2019 09:27, Aleksa wrote: > Error: Please upgrade your API plan to use filters or paging. > > NOT WORK..... What doesn't work? When you upgraded your API plan to use filters or paging did your code break? Did you get a different error message? Did the wrong data come back? And is it the same using filters as it is with paging? We have no idea what we are looking for. Personally I don't even know what the library does, nor what paging and filters entails. But even if I did I couldn't help without more details. > Is there another way I suspect you'd need to ask the package/API provider. This is not a standard part of Python so the likelihood of anyone on this list using it is quite small. > def grab_file (IP,PORT,FILE): > print ("[*] Testing: "+IP+" on Port: "+PORT+"[*]\n") > try: Your code has been mangled by the email system, you need to post in plain text to preserve formatting. -- 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 From mi8k0mi at gmail.com Tue Dec 24 16:00:40 2019 From: mi8k0mi at gmail.com (Aleksa) Date: Tue, 24 Dec 2019 22:00:40 +0100 Subject: [Tutor] vlc media player in python Message-ID: Please, how to set vlc media player to work in Python.I know it has a python-vlc module ,But to have all the settings in python not just calling to the path for vlc Thanks, -------------- next part -------------- playlist = ['/path/to/song1.flac', '/path/to/song2.flac', 'path/to/song3.flac'] for song in playlist: player = vlc.MediaPlayer(song) player.play() From PyTutor at DancesWithMice.info Tue Dec 24 23:02:54 2019 From: PyTutor at DancesWithMice.info (David L Neil) Date: Wed, 25 Dec 2019 17:02:54 +1300 Subject: [Tutor] vlc media player in python In-Reply-To: References: Message-ID: On 25/12/19 10:00 AM, Aleksa wrote: > Please, how to set vlc media player to work in Python.I know it has a > python-vlc module ,But to have all the settings in python not just > calling to the path for vlc DuckDuckGo (non-tracking search engine) yields numerous hits and numerous interfaces (some of which depend upon your preference for OS/GUI toolkit). Which one(s) did you try? -- Regards =dn From sheikh.shamsul.sir at gmail.com Thu Dec 26 12:08:13 2019 From: sheikh.shamsul.sir at gmail.com (Sheikh shamsul Islam) Date: Thu, 26 Dec 2019 23:08:13 +0600 Subject: [Tutor] python Build error Message-ID: i was doing a simple project on python .i made a script which use Tkinter ,opencv and a trained model which removes background of given image. i build this project on pycharm .now i want to make an exe file of my project .i tried with pyinstaller .but the exe file does not work .when i double click on the exe file i get this error message "failed to execute script gui"(gui is the file name gui.py).so can any one help me building the exe file for my project . From PyTutor at DancesWithMice.info Thu Dec 26 21:50:24 2019 From: PyTutor at DancesWithMice.info (David L Neil) Date: Fri, 27 Dec 2019 15:50:24 +1300 Subject: [Tutor] python Build error In-Reply-To: References: Message-ID: <488ab287-3ce5-1574-4943-c39193b7c03f@DancesWithMice.info> On 27/12/19 6:08 AM, Sheikh shamsul Islam wrote: > i was doing a simple project on python .i made a script which use Tkinter > ,opencv and a trained model which removes background of given image. i > build this project on pycharm .now i want to make an exe file of my project > .i tried with pyinstaller .but the exe file does not work .when i double > click on the exe file i get this error message "failed to execute script > gui"(gui is the file name gui.py).so can any one help me building the exe > file for my project . Of possible interest: Python on Windows FAQ (https://docs.python.org/3/faq/windows.html) Also, check limitations of PyInstaller, including Supported Packages (https://github.com/pyinstaller/pyinstaller/wiki/Supported-Packages) -- Regards =dn From mats at wichmann.us Fri Dec 27 10:07:14 2019 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 27 Dec 2019 08:07:14 -0700 Subject: [Tutor] python Build error In-Reply-To: References: Message-ID: On 12/26/19 10:08 AM, Sheikh shamsul Islam wrote: > i was doing a simple project on python .i made a script which use Tkinter > ,opencv and a trained model which removes background of given image. i > build this project on pycharm .now i want to make an exe file of my project > .i tried with pyinstaller .but the exe file does not work .when i double > click on the exe file i get this error message "failed to execute script > gui"(gui is the file name gui.py).so can any one help me building the exe > file for my project . The building of an "executable" to run your app seems to be a fragile process. You'll probably need to pursue it with the project (pyinstaller) that you're trying to use. https://www.pyinstaller.org/support.html It looks like they're asking for funding help to continue the project. Meanwhile, do you actually need to do this? Standard Python is easy for people to install, even on Windows (*), and python packaging allows for specifying dependencies, so it may not be necessary for you to build an exe? * Note for Windows 10, Python is now available through the Windows Store, you don't even have to fiddle with downloading and executing an installer. From aj.programming321 at gmail.com Mon Dec 30 09:10:19 2019 From: aj.programming321 at gmail.com (Aaron Black) Date: Mon, 30 Dec 2019 07:10:19 -0700 Subject: [Tutor] Python Resources Message-ID: Hi, I?m brand new to python and I?m trying to build a resource library and find the best books and online sites for learning python. Can anyone recommend good books or web sites/blogs for learning python? My general interest in learning this programming language is for work. The focused area would be around automation in dealing with files, some machine learning, and data analysis. Any helpful resources in these areas, or for learning in general, would be greatly appreciated. Thanks, Aaron From laura.schramm92 at gmail.com Mon Dec 30 07:09:26 2019 From: laura.schramm92 at gmail.com (Laura Schramm) Date: Mon, 30 Dec 2019 13:09:26 +0100 Subject: [Tutor] Help with a funcion Message-ID: Hello, I was hoping you could help me out creating a function. My professor has requested that I create a function that simulates m throws of a dice with n sides. The function should return a list of tuples with (value_side, percentage) for every side. The percentages should be expressed as a chain of text with a decimal and "%". For example: For 1000 throws of a dice with 4 sides the answer should look like [(1, 25.3%), (2, 25.8%), (3, 25.0%), (4, 24.5%)] I am given the prompt def throws_of_dice(n_sides, n_throws) Any help would be greatly appreciated. Thank you! - Laura Schramm From PyTutor at DancesWithMice.info Mon Dec 30 14:41:40 2019 From: PyTutor at DancesWithMice.info (David L Neil) Date: Tue, 31 Dec 2019 08:41:40 +1300 Subject: [Tutor] Python Resources In-Reply-To: References: Message-ID: <3c85b149-a7be-eed7-0c18-0ceaef2d231e@DancesWithMice.info> On 31/12/19 3:10 AM, Aaron Black wrote: > I?m brand new to python and I?m trying to build a resource library and find > the best books and online sites for learning python. > > Can anyone recommend good books or web sites/blogs for learning python? > > My general interest in learning this programming language is for work. The > focused area would be around automation in dealing with files, some machine > learning, and data analysis. > > Any helpful resources in these areas, or for learning in general, would be > greatly appreciated. Apologies if this response seems blunt. This question has been asked, and answered, many times! Please review the list's archives for books, videos, and on-line courses. Your fields are very broad. Recommend you start with 'the basics' and specialise from there. Have you found the Python Tutorial amongst the Python Docs? (https://docs.python.org/3/tutorial/index.html) -- Regards =dn From mats at wichmann.us Mon Dec 30 15:26:20 2019 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 30 Dec 2019 13:26:20 -0700 Subject: [Tutor] Python Resources In-Reply-To: References: Message-ID: <63d5633e-22f6-2a2a-2e15-d0385a782c8a@wichmann.us> On 12/30/19 7:10 AM, Aaron Black wrote: > Hi, > > I?m brand new to python and I?m trying to build a resource library and find > the best books and online sites for learning python. > > Can anyone recommend good books or web sites/blogs for learning python? > > My general interest in learning this programming language is for work. The > focused area would be around automation in dealing with files, some machine > learning, and data analysis. > > Any helpful resources in these areas, or for learning in general, would be > greatly appreciated. any general Python book would give you a good start - there are a ton to pick from, here's a place the Python community records ones they know about: https://wiki.python.org/moin/PythonBooks You can also browse around there and find other resources. It's actually kind of daunting because there are so many it can be hard to pick. Websites will pop up with titles like "18 Python programming books for beginners and veterans ..." instead of "The Three best Python books..." In the list on the wiki there are some publishers that seem to publish an inordinate number of titles. I'm going to be a bit rude and say quantity does not necessarily correlate with quality (there's a story behind that dig, but I'm not sharing it here). It would probably be useful to have a curated site of the best of the best. And there are such, but then you have to decide you trust the curators :) For more advanced stuff, "automation ... files" might be something like Python for Devops, while there are numerous books and tutorials on Python for Data Science and Python for ML. It's actually hard for us here to make any particular endorsements. Plus some list participants are authors themselves. And we don't want to come off as favoring some over others, really - picking the right learning materials when there's so much choice does give you the chance to pick the ones that suit your learning style best [note: some course providers and book publishers allow a limited preview for free, which is nice to try out; others just plain are free but you have the option to buy a nice printed copy to support that author). For example, I personally just get irritated by courseware that wants to give you badges, set off little fireworks when you answer five in a row correctly, that kind of stuff - so I steer clear of those. But that's just personal choice. From cs at cskk.id.au Mon Dec 30 18:12:28 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 31 Dec 2019 10:12:28 +1100 Subject: [Tutor] Help with a funcion In-Reply-To: References: Message-ID: <20191230231228.GA47329@cskk.homeip.net> On 30Dec2019 13:09, Laura Schramm wrote: >I was hoping you could help me out creating a function. We can, but we won't actually write it for you. We will offer suggestions, but it works is best when you come with code you've written which doesn't work and explain what it currently does and what you actually want it to do. Anyway, discussion and suggestions below: >My professor has requested that I create a function that simulates m throws >of a dice with n sides. The function should return a list of tuples with >(value_side, percentage) for every side. The percentages should be >expressed as a chain of text with a decimal and "%". > >For example: For 1000 throws of a dice with 4 sides the answer should look >like >[(1, 25.3%), (2, 25.8%), (3, 25.0%), (4, 24.5%)] This looks much like the output of Python's repr() function, except that the percentages will be strings, so: [(1, '25.3%'), (2, '25.8%'), (3, '25.0%'), (4, '24.5%')] For example, you can check the result of your programme like this: result = throws_of_dice(4, 100) print(repr(result)) which woould print a line like the above. Python's interacive prompt doesthe second line for you if you're working that way: >>> throws_of_dice(4, 100) [(1, '25.3%'), (2, '25.8%'), (3, '25.0%'), (4, '24.5%')] >>> (Note, no assignment to "result" there; that would omit the output.) >I am given the prompt >def throws_of_dice(n_sides, n_throws) This is the start of your function definition. It will look more like this when written: def throws_of_dice(n_sides, n_throws): ... throw some dice many times, count the results ... return the list ofresults You need to do a few things in your function: - write a short "for" loop which runs n_throws times (see the range() function for an easy way to do this) https://docs.python.org/3/reference/compound_stmts.html#the-for-statement There's even an example for-loop in the above using range(). - write a little line of code to simulate a throw, by computing a random value from 1 to n_sides; see the "random" module, which has various functions including one to compute a random value like that https://docs.python.org/3/library/random.html#module-random - keep an association of the count of times each side shows up; the simplest is a dict keyed on the "side" (a number from 1 to n_sides), which you could prefill with 0 counts before the main loop runs; on each loop iteration, add one to the appropriate count - collate those results as a list of tuples for return; this involves iterating over the dictionary items (which gets you the key (side) and value (count)), which you can use to prepare a single tuple for that side. Start by ignoring the "count as a percentage" thing and just put in the count as the second tuple element; append each tuple to the list - when that returns a good result for you (like [(1,3),(2,2),(3,4),(4,3)]), _then_ change the code to emit percentages instead of the count. That will require a "total_count" value in order to compute the percentage, and to use formatted strings to express the percentage Sketch out a function doing some or all of the above,and when you get stalled with a problem you can't solve, come back with the current code of your function, its output, and describe what you're not accomplishing so that we can help further. Finally: put in lots of print() calls in your function while writing it: print(repr(something)) This will let you see the state of things in your function as it runs, which is a great aid to figuring out what may be going right or wrong. Cheers, Cameron Simpson From cs at cskk.id.au Mon Dec 30 18:16:52 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 31 Dec 2019 10:16:52 +1100 Subject: [Tutor] vlc media player in python In-Reply-To: References: Message-ID: <20191230231652.GA42990@cskk.homeip.net> On 24Dec2019 22:00, Aleksa wrote: >Please, how to set vlc media player to work in Python.I know it has a >python-vlc module ,But to have all the settings in python not just >calling to the path for vlc I presume you mean this: https://pypi.org/project/python-vlc/ That requires the VLC programme to be already installed on your computer. Is it? >playlist = ['/path/to/song1.flac', '/path/to/song2.flac', 'path/to/song3.flac'] >for song in playlist: > player = vlc.MediaPlayer(song) > player.play() You will need an import statement at the top of you code: import vlc in order to obtain the "vlc" name. If that is still failing, please reply including the output of a failing run (paste the output inline in your reply message, do not attach an image or anything like that). Also note that the paths in your code '/path/to/song1.flac' etc are obviously examples from somewhere; they will need to be real pathnames of real files. Cheers, Cameron Simpson From carlosir at bellsouth.net Mon Dec 30 19:03:04 2019 From: carlosir at bellsouth.net (Carlos) Date: Mon, 30 Dec 2019 18:03:04 -0600 Subject: [Tutor] Python Resources In-Reply-To: References: Message-ID: I am new in Python too I just bought the Python crash course by Eric Matthew Very good book and I am already writing small programs Happy new year Carlos Sent from my iPhone > On Dec 30, 2019, at 12:57 PM, Aaron Black wrote: > > ?Hi, > > I?m brand new to python and I?m trying to build a resource library and find > the best books and online sites for learning python. > > Can anyone recommend good books or web sites/blogs for learning python? > > My general interest in learning this programming language is for work. The > focused area would be around automation in dealing with files, some machine > learning, and data analysis. > > Any helpful resources in these areas, or for learning in general, would be > greatly appreciated. > > Thanks, > Aaron > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From arj.python at gmail.com Tue Dec 31 01:58:16 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 31 Dec 2019 10:58:16 +0400 Subject: [Tutor] Python Resources In-Reply-To: References: Message-ID: We've collected some free books on our usergroup's site: https://www.pymug.com/resources.html Do take a look. Thanks. On Mon, 30 Dec 2019, 22:57 Aaron Black, wrote: > Hi, > > I?m brand new to python and I?m trying to build a resource library and find > the best books and online sites for learning python. > > Can anyone recommend good books or web sites/blogs for learning python? > > My general interest in learning this programming language is for work. The > focused area would be around automation in dealing with files, some machine > learning, and data analysis. > > Any helpful resources in these areas, or for learning in general, would be > greatly appreciated. > > Thanks, > Aaron > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor >