You want to find strings on multiple lines of a file, and possible multiple
string groups within a file (you didn't say). So you will have to check each
line and store anything you want to keep for each file, and you will have to
add the code to cycle through the files, so it is something along
And you can simplify the code with something like this for all of the "grid="
statements
new_grid = [[],
[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],
[2,0,2,0],[0,4,0,8],[0,16,0,128],[2,2,2,2],
[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],
[2,0,2,0],[0,4,0,8
This is most likely using class objects instead of instance objects. Not a
normal thing in Python. As stated above, it is difficult, as the responses in
this thread show, to get assistance with some alternate coding style. It is
better to use Python in the way that is intended. Otherwise, yo
How do you then run the mainloop, i.e. get it to do something?
--
https://mail.python.org/mailman/listinfo/python-list
It is very straight forward; split on "_", create a new list of lists that
contains a sublist of [file ending as an integer, file name], and sort
fnames=["XXX_chunk_0",
"XXX_chunk_10",
"XXX_chunk_1",
"XXX_chunk_20",
"XXX_chunk_2"]
sorted_lis
First, you have to have a Tk instance before you do anything else. Take a look
at this example, and then expand upon it to create the calculator
http://python-textbok.readthedocs.io/en/1.0/Introduction_to_GUI_Programming.html
--
https://mail.python.org/mailman/listinfo/python-list
Use multiprocessing since you want to do multiple things at once
https://pymotw.com/2/multiprocessing/basics.html If I understand you
correctly, once the string is found you would terminate the process, so you
would have to signal the calling portion of the code using a Manager dictionary
or l
If you want to do something only if the file exists (or does not), use
os.path.isfile(filename)
--
https://mail.python.org/mailman/listinfo/python-list
Add some print statements to see what is happening, especially after the for
elem in mylist1: statement
--
https://mail.python.org/mailman/listinfo/python-list
Doug Hellmann has what looks like a similar example using a poison pill (2nd
example at)
https://pymotw.com/2/multiprocessing/communication.html#multiprocessing-queues
Note that join() allows the processes to finish so it you don't care then don't
"join()" them. You can also terminate a multi
Use a dictionary to count the number of times each first letter appears, then
place any first letters==4 in a list or set and remove any items that have a
first letter in the list/set (or keep items that are not in the set which is
probably faster if using list comprehension).
--
http://mail.
Any programming language is only as good as the person who is using it.
--
http://mail.python.org/mailman/listinfo/python-list
The obvious question, do you have the shebang on the first line so the
OS knows it's to be run as a Python program? Also I would change
tryJson() to
if __name__ == "__main__':
tryJson()
This probably won't make any difference but you will have the bases
covered.
--
http://mail.python.org/mai
> I'm looking for a kbhit/getch equivalent in python in order to be able to
> stop my inner loop in a controlled way (communication with external hardware
> is involved and breaking it abruptly may cause unwanted errors
A curses example
import curses
stdscr = curses.initscr()
curses.cbreak()
s
> waiting = False
>
>
>
> def clicked(x, y):
>
> global waiting
>
> print('clicked at %f %f' % (x,y))
>
> waiting = False
>
> return
>
>
>
> def wait_for_click(s):
>
> global waiting
>
> waiting = True
>
> s.listen()
>
> while waiting:
>
> time
>From this line, "data" appears to be a class
if 0 < ix < data.width and 0 < iy < data.height:
>From this line, "data" appears to be a list, although a two
dimensional list would be accessed as data[ix][iy]
point = data[ix, iy]
Also, returning a list from a function is a matter of pref
On Oct 14, 1:11 pm, Владимир Пылев wrote:
> label = Label(frame, width = 40, text='text', name = 'name')
> ...
> name_='name'
> configure(name_)
> ...
> def configure(name_)
> #And how can that be?
> # At least let the text you want to change
I do not understand your question
On Oct 6, 3:09 am, sajuptpm wrote:
> I need a way to make following code working without any ValueError .
>
> >>> a, b, c, d = (1,2,3,4)
> >>> a, b, c, d = (1,2,3).
Why is it necessary to unpack the tuple into arbitrary variables.
a_tuple=(1,2,3)
for v in a_tuple:
print v
for ctr in range(le
It possibly requires a "shell=True", but without any code on any way to test,
we can not say.
--
http://mail.python.org/mailman/listinfo/python-list
There is parallel python as well http://www.parallelpython.com/
--
http://mail.python.org/mailman/listinfo/python-list
On Friday, August 10, 2012 8:31:48 AM UTC-7, Tamer Higazi wrote:
> let us say a would be x = [2,5,4]
>
> y = a[3]
>
> if I change y to []
>
> I want the result to be x = [2,5,[]] and that's automaticly
There is no such thing as a[3] if a=[2,4,5]. And this is a list not a
dictionary, so I wo
On Jul 17, 9:32 am, Shamefaced wrote:
> Hi,
> Any reason why a blank Tk() window opens up when I run my code:
> Code:
> for run in range(RUNS):
> waittime = Monitor2()
> checkouttime = Monitor2()
> totaltimeinshop = Monitor2()
> checkout_aisle = Simulation.Resource(AISLES)
> Si
On Wednesday, June 27, 2012 5:15:09 PM UTC-7, Steven D'Aprano wrote:
> On Wed, 27 Jun 2012 16:24:30 -0700, David wrote:
>
> > First, you should be getting an error on
> > vars()[var] = Button(f3, text = "00", bg = "white")
> > as vars() has not been declared
>
> The Fine Manual says differently:
if line is not None: probably does not work the way you expect. You
might try
if line.strip():
Take a look at this quick example
test_lines = ["Number 1\n", "\n", ""]
for ctr, line in enumerate(test_lines):
print ctr, line
if line is not None:
print " not None"
--
http://mai
> def conc1(a, _list = []):
> _list = _list + [a]
> return _list
> for i in range(4):
> _list = conc1(i) ## <- list not passed
You don't pass the list to the conc1 function, so you start with the
default, an empty list, each time.
--
http://mail.python.org/mailman/listinfo/pyth
The error is with the labels not the canvas. All labels will have an
id of "None" as that is what pack() returns.
lbl = Label(win, text=astr[i]).pack(side=LEFT )
labels.append(lbl)
The error will come up in the config_labels function when the program
tries to config a tuple of "N
Sorry, I did not understand the question correctly, and so have added
another focus_set for the entry after the menu's creation. You can
still enter after the menu comes up, even though you can't see where
you are entering.
import Tkinter
class demo:
def __init__(self, parent):
self.
Adding focus_set seems to work for me. What do want to do
differently?
import Tkinter
class demo:
def __init__(self, parent):
self._entry = Tkinter.Entry(width = 60)
self._suggestions = Tkinter.Menu(parent, tearoff = 0,
takefocus = 0)
self._entry.pack(padx = 20, pady
You can use f.read() to read the entire file's contents into a string,
providing the file isn't huge. Then, split on "\r" and replace "\n"
when found.
A simple test:
input_data = "abc\rdef\rghi\r\njkl\r\nmno\r\n"
first_split = input_data.split("\r")
for rec in first_split:
rec = rec.replace("\
Two main routines, __main__ and main(), is not the usual or the common
way to do it. It is confusing and anyone looking at the end of the
program for statements executed when the program is called will find
an isolated call to main(), and then have to search the program for
the statements that sho
as the += notation seems to be a syntaxic sugar layer that has to be
converted to i = i + 1 anyway.
That has always been my understanding. The faster way is to append to
a list as concatenating usually, requires the original string,
accessing an intermediate block of memory, and the memory for th
On Jul 21, 10:02 am, Gary wrote:
> For some reason it will not send me the first text file in the directory.
You have to print an unsorted list of the directory to know the name
or the first file in the directory. Files are not stored on disk in
alphabetical order, but are many times sorted in a
> 1. In this dict, if there is a UNIQUE max value, then its *key* is the
> winner.
> 2. If there are any TIES for max value, then the *key* 'b' is the
> winner by default.
This will store the max value(s) in a list. In case of a tie, you can
take the first value in the list, but it may be differe
Partial can be used in a GUI program, like Tkinter, to send arguments
to functions. There are other ways to do that as well as using
partial. The following program uses partial to send the color to the
change_buttons function.
from Tkinter import *
from functools import partial
class App:
def
On Aug 16, 9:07 pm, Jah_Alarm wrote:
> hi, I've already asked this question but so far the progress has been
> small.
>
> I'm running Tkinter. I have some elements on the screen (Labels, most
> importantly) which content has to be updated every iteration of the
> algorithm run, e.g. "Iteration ="
On Aug 16, 9:07 pm, Jah_Alarm wrote:
I have some elements on the screen (Labels, most
> importantly) which content has to be updated every iteration of the
> algorithm
The variable type is IntVar()
You would use int_var_name.set(some_number)
--
http://mail.python.org/mailman/listinfo/python-lis
QT uses "toggled". I do not use QT much but it would be something
like
self.radioButton_one.setCheckable(True)
QtCore.QObject.connect(self.radioButton_one, QtCore.SIGNAL("toggled
()"),self.button_one_function)
If this doesn't work, you can probably find more with a Google for
"toggled".
--
http:
If this is the record, then you can use split to get a list of the
individual fields and then convert to int or float where necessary.
rec = "2NHST1 C1 56 3.263 2.528 16.345 "
rec_split = rec.split()
print rec_split
If you want to read two records at a time, then use
all_data = open(name,
Counting from zero through n-1 is used because it is the memory offset
and not any kind of counter. Simplified, if you are iterating through
a list, using a for loop or anything else, the first element/number is
at memory offset zero because it is at the beginning. And if this is
a list of 4 byte
39 matches
Mail list logo