python-2.7

Working with python2.7 dictionaries

I have an array of numbers: 0x0000: 023d 0017 068e 98a7 b047 6520 8100 a100 0x0010: 425c 564c 414e 3040 b1d2 b1d2 0138 0000 ... '0x00a0']. Why are the keys displayed out of order, and at each when you restart the code, does this incorrect order persist?

os. listdir how to correctly register the path in Windows

Code: path_dir = 'C:\path_to_dir' for name in os.listdir(path_dir): foo Mistake: for name in os.listdir(dir): OSError: [Errno 2] No such file or directory: 'C:\path_to_dir' How do I write the path correctly?

Python global variable

I have two packages: Unloader.py And GetRequest.py In the script implemented in Unloader.py a function is called ... lResponse countNullResponse += 1 How can I correct the code so that Request sees the global variable countNullResponse?

Converting unicode to str in Python 2.7

There is a line (Plaintiff word): s = u'\u0418\u0441\u0442\u0435\u0446' How do I convert it to the normal view? smart_bytes, encode, and decode don't help.

When creating a dictionary in Python 2.7, TypeError: 'dict' object is not callable

I want to create a dictionary from a two-dimensional list, where each sentence in the text is in a separate array. counts = ... line: 4 if word not in counts: 5 counts[word] = 1 TypeError: 'dict' object is not callable

Using Python and ssh (paramiko)

Good afternoon! How do I write code to connect to a remote host with an embedded paramiko module? You must run the command us ... h code works. The script should be executed as follows: ssh [email protected].** > ls-al (on the remote host) > write to log.

What is the difference between %r and %s in Python?

Please explain the difference between them. I only know that %r outputs a " raw " value. But can you show by example what it does?

Find the intersection point of the line from the origin and the segment. matpoltib

Given a straight line given by the equation y=kx and the segment PB1. You need to find the coordinates of the intersection po ... ='blue', marker='o') plt.text(0.5, b1, "B1", horizontalalignment="center") #create PB1 plt.plot([0,p],[b1,0]) plt.show()

Python date subtraction

It is required to subtract from the specified time, the present. test = datetime.today().strftime("%H:%M") test2 = tim ... only the number of minutes remaining until this time. At the moment, I'm stuck on this code. What can I do to make it work?

os. listdir and Cyrillic

The following code(I omitted some parts): import os path = 'C:\Users\Алекс\Desktop\DefendMySystem' files = ... ndowsError: [Error 3] : 'C:\\Users\\\xd0\xa1\xd0\xb0\xd1\x88\xd0\xb0\\Desktop\ \DefendMySystem/*.*' How can this be fixed?

Python -->ValueError: incomplete format

Can anyone help me with this code? I am having two problems: the first is the error mentioned in the title and the second is ... (V): print "O melhor jogador foi o numero %d, com %d votos, correspondendo a %d% do total de votos" %(i+1,V[i],P[i])

Saves browser state or cookies using selenium

I am doing tests using whatsapp web, so every time I run selenium, read the qr code and start the tests, and I have to do thi ... es,but then I put in a while that while the array was empty it would try and try but still, it just picks up the empty array.

How to extract specific data from a text file with Python?

I have a* * text file of 49633 lines * *(file.txt) with the following format: -e Tue Mar 28 20:17:01 -03 2017 ... ut I couldn't write any lines of code other than: #!/usr/bin/env python F = open(“arquivo.txt”,”r”) Could anyone help?

list assignment index out of range

A part of my Python program is: dt=1 maxt=3600*2 t=range(0,maxt,dt) r=len(t) Tsup_i=20 for i in range(1,r): Tsup[0]=Ts ... ment of the list is equal to Tsup_i, that gives to determine P[i] and further in the code can determine Tsup[i+1] using P[i].

list index out of range

Tsup=[] Te=0 dt=1 t=range(0,3600*2,dt) r=len(t) for i in range(0,r): Tsup.append(20) .... Tsup.append( (((Pj[i]+Ps-Pc[i ... > 0.1: T_est=Tsup[i] The error "list index out of range" appears in the variation line.append (abs (Te-Tsup[i])).

Rename application in Django Admin

Good night guys, I'm trying to rename the application in django admin according to the documentation, but it ended up having ... 'm doing something wrong, I need some import in those files?? I am new to django and anyone who can help me I thank you!! '

Convert word document (DOC) to pdf using python

I would like to convert a word document (doc) to pdf using python 2.7. I have this script, but I didn't understand anything f ... ('Word.Application') doc = word.Documents.Open(in_file) doc.SaveAs(out_file, FileFormat=wdFormatPDF) doc.Close() word.Quit()

RuntimeError: maximum number of recursive calls exceeded-python

fibonacci_cache = {} def fibonacci(n): if n in fibonacci_cache: return fibonacci_cache[n] if n==1: v ... ersion: Python 2.7.10. Returned me this error: RuntimeError: maximum recursion depth exceeded. How do I solve this problem?

Generate random numbers in Python without repeating

I have the following situation: I have a vector with 4 indexes. Each index generates a random value from 0 to 100. I have ... randint(0, 100)] print AP_X I wish that never repeated numbers are generated. For example: [4,4,6,7] How can I do this?