Python Programming/Q&A

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Welcome to the Python Programming questions and answers page.
Post any questions you have while learning Python. Please sign and date your entries by inserting -- ~~~~ at the end.
If you have questions about this book, post them on the Python Programming discussion page.

Ask a question!

How to develop a GUI Python program to click on desktop at desired position ...[edit]

Hello All Pythoners,

I am Raju C Padaria from India. Today whole day I read about Python programming language. I feel it very very useful in my daily office work for my users. I have been working on SAP R/3 4.6C on Windows XP since last 3 years. I need to automate some download from SAP using Python. Is it possible to open SAP screen, enter required parameters in the screen, click on an icon to download data from SAP & so on & so forth. I have gone through almost all examples / tutorials but couldn't find the answer of my question.

Please guide me how should I go about it ?

Thanks well in advance !

Best Regards,

--Padarrju Raju C Padaria 13:41, 17 October 2006 (UTC)

I want a sample program on linked list

--Padarrju Raju C Padaria 13:41, 17 October 2006 (UTC)

Who is the author of Python?[edit]

Guido van Rossum

Python Problem[edit]

Given the dimensions of a rectangular grid and a sequence of robot positions and instructions, you are to write a program that determines for each sequence of robot positions and instructions the final position of the robot. A robot position consists of a grid coordinate (a pair of integers: x-coordinate followed by y-coordinate) and an orientation (N,S,E,W for north, south, east, and west). A robot instruction is a string of the letters 'L', 'R', and 'F' which represent, respectively, the instructions: • Left: the robot turns left 90 degrees and remains on the current grid point. • Right: the robot turns right 90 degrees and remains on the current grid point. • Forward: the robot moves forward one grid point in the direction of the current orientation and maintains the same orientation. The direction North corresponds to the direction from grid point (x,y) to grid point (x,y+1). Since the grid is rectangular and bounded, a robot that moves ``off an edge of the grid is lost forever. However, lost robots leave a robot ``scent that prohibits future robots from dropping off the world at the same grid point. The scent is left at the last grid position the robot occupied before disappearing over the edge. An instruction to move ``off the world from a grid point from which a robot has been previously lost is simply ignored by the current robot. INPUT SPECIFICATION The first line of input is the upper-right coordinates of the rectangular world, the lowerleft coordinates are assumed to be 0,0. The remaining input consists of a sequence of robot positions and instructions (two lines per robot). A position consists of two integers specifying the initial coordinates of the robot and an orientation (N,S,E,W), all separated by white space on one line. A robot instruction is a string of the letters 'L', 'R', and 'F' on one line. Each robot is processed sequentially, i.e., finishes executing the robot instructions before the next robot begins execution. There will be 3 robots. You may assume that all initial robot positions are within the bounds of the specified grid. The maximum value for any coordinate is 50. All instruction strings will be less than 100 characters in length. OUTPUT SPECIFICATION For each robot position/instruction in the input, the output should indicate the final grid position and orientation of the robot. If a robot falls off the edge of the grid the word ``LOST should be printed after the position and orientation. SAMPLE INPUT (from file) and OUTPUT (to file) Case 1: in.txt looks like this: 5 3 1 1 E RFRFRFRF 3 2 N FRRFLLFFRRFLL 0 3 W LLFFFLFLFL out.txt looks like this: 1 1 E 3 3 N LOST 2 3 S

Pyserial Bill Acceptor[edit]

Has anyone ever tried to have python read a bill acceptor through a RS-232 serial port? If not how would one go about this? I assume using pySerial but except for the examples there isn't much information that is intuitive to me anyway. Any information would be great. Thanks.


Reinitializing Python Import[edit]

I am new to Python. I want to manipulate ready-made command line programs with scripts, and Python appears to achieve this with more control of the programs than DOS batch files.

I have written a few Python scripts to test some programs, and I have a question about reinitializing the text module when I make a change to it. After I've imported a module into Python, e.g., >>> import, and I make a new change to the text file "," the change will not take effect even if I again import it into Python.

How do I reinitialize the module once I've made changes to the module? I can't just import the module; the definitions remain unchanged, unless I exit Python and restart it.

Thanks, Walter Goedecke

programing in python an ATM machine[edit]

i need some guidance on how to write a program in python for an ATM machine

What is my error in this function?[edit]

def area (rectangle):

   a = 0.0
   for r in rectangle:
       a = a * r
   return a 

rectangle = [] while True:

   l = raw_input ("length:")
   w = raw_input ("width:")
   l = float (l)
   w = float (w)
   a = (area)
   print "the area is", a

x%2[edit] in this tutorial what does mean x%2 ? i think: i * 2% = always even number but why not 4,6 or 8? but i * 4(6,8,10,12...)% = always even number too for example: 100 * 2(4,6,8,10,12...)% = 2(4,6,8,10,12...) even numbers = {2,4,6,8,10,12...} and how pyton understanding 0(even or odd number or it is an exception?)?

Python How to Program[edit]

function that determines whether a number is prime

for i in range(1,30,2):

   print(i)#prints all prime numbers less than 30

asking questions[edit]

How can you turn this in to a question that the user could answer in python?

'aright and lastly, would you like a cone or bowl?

Please have a look on Python Programming/Input and Output. JackPotte (discusscontribs) 23:31, 18 February 2016 (UTC)

using pandas for opening csv file[edit]

thanks really, i find your video helpful. when i wanted to know how to read with pandas a csv file imports from google. the method of reading is not working, I have tried so much. here is my email.

Sending text to a printer[edit]

I would think this would be a simple answer to find but so far it has gone over my head. What I want to do is send text, pdf and/or a graphic to a local printer. Seems like this is something everyone needs to do in Python sooner or later but so far I have not come up with an answer. I'm using Ubuntu 16.04 and a USB port.

How to print a string without starting a new line?[edit]







How do I get

Using 2 prints?

Finding duplicated letters in a short string (Len = 10 or so)[edit]

Need a function to search a string of UC letters to find any or all duplicated letters