Re: What's wrong on using Popen's communicate method?
This is same as echo abcd | notepad.exein Command Prompt. You won't see the abcd neither. On Thu, Jul 4, 2019 at 8:41 AM Chris Angelico wrote: > On Thu, Jul 4, 2019 at 10:01 AM wrote: > > > > I have the test0.py below. I expect to see 'abcd' showing in the notepad > window: > > - > > import subprocess as sp > > p0 = sp.Popen('notepad.exe', stdin=sp.PIPE) > > p0.communicate(input=b'abcd') > > - > > But nothing happens. The notepad is completely empty. What have I missed? > > > > The "communicate" method sends text to the standard input pipe. This > has nothing to do with the GUI, and most Windows GUI programs take no > notice of it. You'll need something GUI-aware for this. > > Is Notepad just an example, or are you actually trying to control MS > Notepad? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How Do You Replace Variables With Their Values?
dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main Course':['Fish', 'Meat'], 'Desert':['Cake', 'Banana Split']} # Don't ask where I got the dinner from for meal in dinner.keys(): exec(meal.replace(' ','_') + ' = list(dinner[meal])') print(Starters) print(Main_Course) print(Desert) OUTPUT: ['Fried Calamari', 'Potted crab'] ['Fish', 'Meat'] ['Cake', 'Banana Split'] On Thu, Jul 11, 2019 at 10:34 AM Ben Finney wrote: > Terry Reedy writes: > > > On 7/10/2019 6:37 PM, CrazyVideoGamez wrote: > > > > > and I'm just changing it with the code above (you can find that by > > > printing it out). How can I make separate lists called 'Starters', > > > 'Main Course', and 'Desert'? > > > > starters = dinner['Starters'] > > main_course = dinner['Main Course'] > > desert = dinner['Desert'] > > The question comes, though, why you (CrazyVideoGamez) are doing this. > > You have the lists immediately accesible as dictionary elements, by > name. > > Why do you need to also have them bound to separate names; what problem > are you trying to solve that you think this will help? > > -- > \ “If [a technology company] has confidence in their future | > `\ ability to innovate, the importance they place on protecting | > _o__) their past innovations really should decline.” —Gary Barnett | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How Do You Replace Variables With Their Values?
Wow, I'm so sorry I answered on the question : "How do you replace a variable with its value". For what i understood with the example values, CrazyVideoGamez wants 3 variables named like the meal-names in dictionary. Yes, it's not secure unless you work with your own dataset (just like sending your own created commands with set=True in subprocess). Yes there might be better solutions for the real problem. But maybe the user really has a purpose for it, in a secure environment with own datatset, it's a valid answer for "How do you replace a variable with its value". On Fri, Jul 12, 2019 at 12:10 PM Ben Finney wrote: > Aldwin Pollefeyt writes: > > > dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main > > Course':['Fish', 'Meat'], 'Desert':['Cake', 'Banana Split']} > > > > # Don't ask where I got the dinner from > > > > for meal in dinner.keys(): > > exec(meal.replace(' ','_') + ' = list(dinner[meal])') > > > > print(Starters) > > print(Main_Course) > > print(Desert) > > Why do you think this is needed? Why (there may be some reason! but you > have not told us what that is) can your program not just:: > > print(dinner['Starters']) > print(dinner['Main Course']) > print(dinner['Desert']) > > > OUTPUT: > > ['Fried Calamari', 'Potted crab'] > > ['Fish', 'Meat'] > > ['Cake', 'Banana Split'] > > The above code produces this output, without any need for binding new > names. So what is it you are actually trying to achieve, and why do you > think the new bindings are necessary? > > -- > \“The number of UNIX installations has grown to 10, with more | > `\ expected.” —Unix Programmer's Manual, 2nd Ed., 1972-06-12 | > _o__) | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Want to learn python as I have donne manual testing for 12 years. Please help to share opinion how to start. Thanks
Try to find small projects to solve with Python instead of using other applications. Hereby my experience: * solve or just represent a riddle or mathematical question. - Youtube channels called standupmaths and numberphile has some interesting videos about algorithms. Then it's fun trying to build those and see what happens. not only numerical results but also plot it into graphs or create images from it - Every year General Intelligence and Security Service of the Netherlands releases a series of puzzles around Christmas. It's fun to try to create some decrypting tools around it and run them on top of the questions. Can even automatically crawl over some wiki pages to create lists of names for possible answers if you suspect it's a crossword full of encrypted nobel prize winners. - or find some websites with riddles and crosswords or just on hackerrank.com * show headlines of a newspaper in the format you want in a terminal using a rss feedparser * a ubuntu desktop indicator with your favorite stock market price or currency exchange or the time you logged into work in the morning * write your own api or webservice around all info that you learned to gather from multiple places * a IRC bot that put's all the info of other scripts that interest you (RSS, stock market, cpu usage, cheatsheets, python bugs, ...) on your own IRC channel (.get stock_info || .get python_snippets strings) so you can all info in one place * write a part of a rubiks cube algorithm to understand the changing parts to solve a small part * solve a sudoku you had trouble with in the newspaper last week and still bothers you * start using some threading to solve puzzles faster if possible. * send yourself a alert email when some disk is 80% full or when some idol of you tweeted again * just follow this mailing list or stackoverflow (python tags) and try to understand the code examples that pass by ... with just some daily tasks or solving questions, in the end, you learn first some basic functions and algorithms, get some info from a webpage (wiki) or a open api (weather info?), connect a socket to pass data, plot some data on a chart/image, show info in your OS's status bar, write your own api, threading, ... On Mon, Jul 15, 2019 at 3:00 PM wrote: > Want to learn python as I have donne manual testing for 12 years. Please > help to share opinion how to start. Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Style suggestions/critiques
The Zen of Python is readability? Does this look neater? x11, y11, x12, y12, x21, y21, x22, y22 = line1[0] + line1[1] + line2[0] + line2[1] Compared to tuples, lists are maybe more useful if you need to manipulate the coordinates. line1 = [ [1, 2], [3, 4] ] line1[1][0] = 5 line1[0] = [2, 3] or _p1, _p2, _x, _y = 0, 1, 0, 1 line1 = [ [1, 2], [3, 4] ] line1[_p2][_x] = 5 line1[_p1] = [2, 3] On Wed, Aug 21, 2019 at 5:15 AM Michael F. Stemper < michael.stem...@gmail.com> wrote: > I recently wrote a couple of modules (more to come) to help me > use the tikz package in TeX/LaTeX. Since it's all to do with > drawing, I have a lot of points in R^2. Being unimaginative, I > implemented them as ordered pairs (2-tuples) of floats. E.g.: > > p1 = 3,4 > p2 = 5,6 > > Naturally, lines are implemented as ordered pairs[1] of points: > > line = p1,p2 > > This all seems reasonably simple and intuitive (to me). However, > in order to actually do some manipulation, I have stuff like: > > # Unpack the lines > l1p1,l1p2 = line1 > l1x1,l1y1 = l1p1 > l1x2,l1y2 = l1p2 > l2p1,l2p2 = line2 > l2x1,l2y1 = l2p1 > l2x2,l2y2 = l2p2 > > spattered all over. Although this is simple enough, I find it > aesthetically unappealing. > > Is there some better idiom that I should be using, or is this > really in accord with The Zen of Python? > > [1] (I could have done sets, I suppose, but orientation might be > useful at some point.) > > -- > Michael F. Stemper > The FAQ for rec.arts.sf.written is at: > http://leepers.us/evelyn/faqs/sf-written > Please read it before posting. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: numpy results in segmentation fault
use: num_arr1 = numpy.array(tgt_arr1, dtype=int) num_arr2 = numpy.array(tgt_arr2, dtype=int) On Mon, Sep 16, 2019 at 5:36 PM Pradeep Patra wrote: > Yes it is crashing in the hackerrank site and the testcases fails with > segmentation fault. I tried to install numpy with 3.7.3 and it is for some > reason not working and after import when I run import numpy at python > console and press enter I get >>? i,e its not working properly. > > Can you please help letting me know the python and numpy compatibility > matrix or I am missing anything? > > I tried some of the numpy code from the other github and it also fails with > the segmentation fault :-(. I am guessing some numpy version compatility > issue or some environment issue. > > On Thu, Sep 12, 2019 at 8:00 PM Thomas Jollans wrote: > > > On 12/09/2019 15.53, Pradeep Patra wrote: > > > Hi , > > > > > > I was trying to solve the hackerrank and was using python 3.7.x. > > > https://www.hackerrank.com/challenges/np-concatenate/problem > > > > > > While running the code sometimes I get success result and sometimes it > > > fails with "Segmentation Fault" at Hacker rank UI. I dont have any clue > > why > > > the code is crashing ? Does anyone have any idea? > > > > > > Are you sure it's your code that's crashing, and not something beyond > > your control? (Such as the software that is starting Python for you) > > Does it depend on the input? Can you reproduce the issue in a controlled > > environment (i.e. on your own PC)? > > > > > > > > > > Regards > > > Pradeep > > > > > > import numpy > > > > > > n,m,p = map(int,input().split()) > > > tgt_arr1 = [] > > > for i in range(n): > > > row = list(map(int,input().split())) > > > tgt_arr1.append(row) > > > tgt_arr2 = [] > > > for j in range(m): > > > row = list(map(int,input().split())) > > > tgt_arr2.append(row) > > > > > > num_arr1 = numpy.array(tgt_arr1,int) > > > num_arr2 = numpy.array(tgt_arr2,int) > > > > > > print(numpy.concatenate((num_arr1,num_arr2),axis=0)) > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Basic python question
You could use: >>> x, y = set(output.split()) On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: > Hello, > > I am new to python and trying to do some basic things with python. I > am writing a script that runs a df command and I need parts of that > output saved in 2 different variables. Is this something that can be > done? I can do this by running multiple df commands but would prefer > to make only one call: > > -- > inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' '" > output = subprocess.check_output( inode_cmd, > stderr=subprocess.STDOUT, shell=True ) > -- > > But this would end up giving me the following: > > #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' >5 1 > > I would like variable x to be 5 and variable y to be 1. Is there a > easier way to do this? > > Thanks in advance for your guidance. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Basic python question
Oh, sorry .. please try this: >>> x,y = tuple(output.split()) On Thu, Oct 3, 2019 at 12:11 PM Jagga Soorma wrote: > Thanks Aldwin that helps but it looks like it is reversing the numbers > for some reason: > > the df command returns the following: > 7 2 > > I used your example and did: > x,y = set(output.split()) > > My assumption would be that x should be 7 and y should be 2. However, > when I print x and y it seems to be reversed (x is 2 and y is 7). Am > I missing something? > > Thanks > > On Wed, Oct 2, 2019 at 8:49 PM Aldwin Pollefeyt > wrote: > > > > You could use: > > > > >>> x, y = set(output.split()) > > > > On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: > >> > >> Hello, > >> > >> I am new to python and trying to do some basic things with python. I > >> am writing a script that runs a df command and I need parts of that > >> output saved in 2 different variables. Is this something that can be > >> done? I can do this by running multiple df commands but would prefer > >> to make only one call: > >> > >> -- > >> inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' > '" > >> output = subprocess.check_output( inode_cmd, > >> stderr=subprocess.STDOUT, shell=True ) > >> -- > >> > >> But this would end up giving me the following: > >> > >> #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' > >>5 1 > >> > >> I would like variable x to be 5 and variable y to be 1. Is there a > >> easier way to do this? > >> > >> Thanks in advance for your guidance. > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Basic python question
Seems to work also: >>> [x,y] = output.split() On Thu, Oct 3, 2019 at 12:17 PM Aldwin Pollefeyt wrote: > Oh, sorry .. please try this: > > >>> x,y = tuple(output.split()) > > On Thu, Oct 3, 2019 at 12:11 PM Jagga Soorma wrote: > >> Thanks Aldwin that helps but it looks like it is reversing the numbers >> for some reason: >> >> the df command returns the following: >> 7 2 >> >> I used your example and did: >> x,y = set(output.split()) >> >> My assumption would be that x should be 7 and y should be 2. However, >> when I print x and y it seems to be reversed (x is 2 and y is 7). Am >> I missing something? >> >> Thanks >> >> On Wed, Oct 2, 2019 at 8:49 PM Aldwin Pollefeyt >> wrote: >> > >> > You could use: >> > >> > >>> x, y = set(output.split()) >> > >> > On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: >> >> >> >> Hello, >> >> >> >> I am new to python and trying to do some basic things with python. I >> >> am writing a script that runs a df command and I need parts of that >> >> output saved in 2 different variables. Is this something that can be >> >> done? I can do this by running multiple df commands but would prefer >> >> to make only one call: >> >> >> >> -- >> >> inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' >> ' '" >> >> output = subprocess.check_output( inode_cmd, >> >> stderr=subprocess.STDOUT, shell=True ) >> >> -- >> >> >> >> But this would end up giving me the following: >> >> >> >> #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' >> >>5 1 >> >> >> >> I would like variable x to be 5 and variable y to be 1. Is there a >> >> easier way to do this? >> >> >> >> Thanks in advance for your guidance. >> >> -- >> >> https://mail.python.org/mailman/listinfo/python-list >> > -- https://mail.python.org/mailman/listinfo/python-list