Do you have a link to the CDN for jquery? What does your console output say?
Do you have a link to the CDN for jquery? What does your console output say?
Okay, I haven't been on in a while, let me tell you why no one has replied, you haven't showed ANY effort. Let me see the code you have so far and I'll tell you what you're doing wrong and give you suggestions. This is a simple solution, and you would get the answer in 2 seconds by looking at your text book or anyother reference and apply some logic.
I want to know if it's high school or college, I really hope high school.
Tisk tisk, sounds like some points off for attempted academic dishonesty to me...
Oh, please tell me someone finally got caught doing that by their teacher. Also think about range, it should take you about 45 seconds to do this program if you just take a moment to think about it.
fyi, there is no elseif in python...
I don't know about anyone else, but I'm getting a little tired of the "I goggled for this" lie http://tinyurl.com/3ldotwl Perhaps we should boycott the too obvious fibs and point them out as above.
Edit: But then I guess that's the same thing, as that's doing the search effort which provides the lazy with the code from the search. Back to pointing out the "we only help those who show effort" links. They are http://www.daniweb.com/software-development/computer-science/threads/573
http://www.daniweb.com/software-development/computer-science/threads/573/3625#post3625
http://www.daniweb.com/software-development/cpp/threads/78223
I'm sorry, I'm not really contributing to the discussion as I'm completely sick of this matter altogether but I just have to say wooeee, I loved that I haven't laughed that hard in a while.
The way I'm interpreting it is like:
that='''450 42.5 16625.0
460 42.0 16820.0
470 41.5 17005.0
480 41.0 17180.0
490 40.5 17345.0
500 40.0 17500.0'''
this=that.split('\n')
price=None
for info in this:
data=info.split()
if price==None:
price=data[1]
elif data[1]<price:
for info in data:
print('XXXX is %s'%info)
break
output:
>>>
XXXX is 460
XXXX is 42.0
XXXX is 16820.0
>>>
but your saying the price starts to drop and I don't know if the second one is the price or the first or the third... you didn't give us enough info to go on...
issues:
-input is a BIF
-fix your indentation
-think about it; how would you use the functions on anything? That should help you use them in the main() function
-I'm sure there are more but I don't feel like analyzing this whole thing with the indentation all messed up, it's a pain to read.
I like dictionaries, I made a function see if you can tell what it does from this:
>>> grade_buk=[('tom',4),('ben',5),('tom',8),('ben',12)]
>>> grades=average(grade_buk)
>>> for key in grades:
print(key.title()+':',grades[key])
Ben: 8.5
Tom: 6.0
It's giving me an empty list....
That's probably because, as I said, you need to reformat it to work for your file. I'll attach my file and show you the output:
output:
[[56.71739, 56.65762, 56.61648, 56.63215, 56.98378, 57.78903, 58.81514, 59.98271, -1.0, 56.05496, 56.00158, 55.9683, 56.70977, 57.64234, 58.75118, 59.94779, 55.47366, 55.39739, 55.3502, 55.36098, 55.7111, 56.51588, 57.5418, 58.70937], [56.6795, 56.60323, 57.34681, 59.38853, 56.09566, 55.98341, 56.07384]]
56.71739
56.67950
56.65762
56.63320
56.61648
56.60323
56.63215
56.74365
56.98378
57.34681
57.78903
58.27959
58.81514
59.38853
59.98271
60.58515
-1.00000
56.09566
56.05496
56.02777
56.00158
55.98341
55.96830
55.99615
1 1 1
56.34692
56.70977
57.15187
57.64234
58.17782
58.75118
59.34534
59.94779
-1.00000
55.47366
55.42963
55.39739
55.36958
55.35020
55.33404
55.36098
55.47148
55.71110
56.07384
56.51588
57.00632
57.54180
58.11517
58.70937
2 1 1
or you could make an array of arrays "if it could suit your needs" with something like:
with open('help.txt') as f:
linez=f.readlines()
aRray=[]
def make_list(lines,array):
to_append=[]
for line in lines:
if ' ' in line:#I used this because of how the file is formatted for me, it this doesn't work for you maybe '\t' will, Idk
lines.remove(line)
array.append(to_append)
make_list(lines,array)
else:
num=(line.strip('\n'))
try:
to_append.append(float(num))
except ValueError:
pass
lines.remove(line)
make_list(linez,aRray)
print(aRray)
then the arrays in that large array could be accessed just as any other iterable: or you could make a dictionary of it with a similar process if you wished. And this function could easily be manipulated, I just didn't care what happened to linez after it was iterated through, maybe you do, idk.
when you get a whitespace stop, build the array with those lines and go ahead to build the next array with the next 24 lines.
so you want separate arrays instead of one large one?
lambda's are anonymous functions see http://www.python.org/doc//current/reference/expressions.html#lambda and Lambda Calculus and Anonymous Functions (Python)
well I don't see a space or tab in any of the other kind. so what if we checked the contents of each line and checked for spaces or tabs?
Because the Label widget does not provide features which I need (although Text also disables some of them with "disabled", which is the issue here).
User will interact with program by selecting a line or a portion of the text. I think Label does not allow user to select and see, nor the program to see what user selects.
And later I'll need to format the text, columns, font, color. Need a scrollbar with functional page up/down keys, etc...
What exactly do you mean select and see, how is the user selecting? I need more context.
well think about how you would skip them...what is the easiest way to distinguish that particular piece of data from the others? To me it looks like maybe it's the fact that
data[0] is in
"not sure which it is" where data is the line
have you tried a lambda? like:
>>> lis
[(1, 'A'), (3, 'D'), (1, 'Z'), (3, 'F')]
>>>
>>> fixed=sorted(sorted(lis,key=lambda s: s[1]),key=lambda i: i[0],reverse=True)
>>>
>>> fixed
[(3, 'D'), (3, 'F'), (1, 'A'), (1, 'Z')]
>>>
Why don't you just use a label widget?
found the solution. On Windows vista in the command prompt enter:
C:/Python32/Scripts cxfreeze --base-name=Win32GUI theapplication.py
where theapplication.py is the name of your file
is there a way to make cx_freeze utilize the no console property of .pyw files?
I'm trying to use cx_Freeze and everything everything seems like it should work fine, however I'm getting an import error for import tkinter
Traceback
#...
from tkinter import __fix
#...
import_tkinter
ImportError: DLL load failed: The specified module could not be found.
This only happens when I take the the contents "all of it" out of the C:/Python32/Scripts/distany directory, inside there it works fine. any insight?
EDIT: it appears this issue is resolved, however is there a way to make the program easier to access for the user when I make a zip of it and its dependencies, since there are so many?
Looks interesting and fun. Thanks for the introduction vegaseat. If i may ask, what good books would you recommend for starters?
How to think like a computer scientist is great for beginners as is Python programming for the absolute beginner. If you already have experience with a programming language head first python and dive into python 3 are also very good.
When I open python I am unable write my code in it. This just started to happen no idea what is happening? Its unclickable inside but I can click the bar on top. Anybody know?
What do you mean? Like you're unable to edit a program you've made, or IDLE isn't working??? You don't really get locked out of Python..
maybe I'm misunderstanding, but wouldn't something simple like
def make_norm_lis(entry):
lis=[]
for letter in entry:
if letter.isalpha():
lis.append(letter)
else:
lis.append(' ')
lis=''.join(lis)
lis=lis.split()
return lis
work?
>>> st='!@#this@#$is//sparta'
>>> print(make_norm_lis(st))
['this', 'is', 'sparta']
>>>
>>> work='i.going.to.work'
>>>
>>> print(make_norm_lis(work))
['i', 'going', 'to', 'work']
well think about what you would need to do; you'd need to either have a list of the images or be in a specified directory to browse through the images in that; some useful tools might be:
tkFileDialog, askopenfilename
PIL,Image, ImageTk (ImageTk.PhotoImage)
os
Don't bump old threads...start a new thread with your problem.
There's a sticky on beginner project ideas at the beginning of the forum. Check 'em out. Also there are a couple more advanced projects here.
well easy enough; I'd say lists are easier; breaking it down I would do something like "not really showing you too much new here, just showing how what I showed you before but with lists":
def make_dic(file):
with open(file,'r') as f:
file=f.readlines()
dic={}
for line in file:
line=line.split(' ')
clean_lis=[]
for num in line:
if num!='':
clean_lis.append(num)
dic[int(clean_lis[0])]=[clean_lis[1]+' ',float(clean_lis[2].strip('\n'))]
return dic
def lup_bal(lis,up):
cur=lis[-1]
update=float(cur)+float(up)
lis.pop()
new=[account for account in lis]
new.append(update)
lis.pop()
return new
Note that in the following I used what you posted and added one to the original file called 192, that way you could see the change, so really only pay attention to 192's change.
>>> bank=make_dic('help.txt')
>>>
>>>
>>> bank
{192: ['094-11-2328 ', 3322.25], 115: ['139-28-4313 ', 1056.3], 143: ['595-74-5767 ', 4289.07], 155: ['972-87-1379 ', 3300.26], 135: ['706-02-6945 ', -99.06]}
>>>
>>> with open('help3.txt') as f:
for line in f:
line=line.split()
key=int(line[0])
value=float(line[1])
if key in bank.keys():
bank[key]=lup_bal(bank[key],value)
>>> bank
{192: ['094-11-2328 ', 2491.41], 115: ['139-28-4313 ', 1056.3], 143: ['595-74-5767 ', 4289.07], 155: ['972-87-1379 ', 3300.26], 135: ['706-02-6945 ', -99.06]}
This isn't the best or easiest way to do it, but I believe it gets the idea across.
[B]help.txt[/B]
115 139-28-4313 1056.30
135 706-02-6945 -99.06
143 595-74-5767 4289.07
155 972-87-1379 3300.26
192 094-11-2328 3322.25
[B]help3.txt[/B]
380 2932.48
192 -830.84
379 2338.82
249 3444.99
466 -88.33
Here's the words from "Python Programming: An Introduction to Computer Science"
Ch 6, programming exercise 13:
13. Write and test a function to meet this specification:
toNumbers(strList) strList is a list of strings, each of which represents a number. Modifies each entry in the list by converting it to a number.
right, you are modifying each item in the list into a number instead of a string, and returning a list of numbers INSTEAD of a list of strings.
Thank you so much. I managed to solve my problem!
can you show us your solution?
file1: /users/ux454500/radpres.tar /paci/ucb/ux453039/source/amr.12.20.2002.tar~ /paci/ucb/ux453039/source/amr.1.25.2003.htar.idx /paci/ucb/ux453039/source/amr.1.18.2003.htar.idx file2: DIRECTORY /paci/ucb/ux453039/. FILE /paci/ucb/ux453039/.ktb_ux453039 05/31/2006 17:52:04 09/01/2007 14:25:33 FILE /paci/ucb/ux453039/source/amr.12.20.2002.tar~ 03/10/2005 20:56:50 09/02/2007 10:35:41 FILE /paci/ucb/ux453039/source/amr.1.25.2003.htar.idx 02/23/2007 14:20:15 08/27/2007 14:53:48 FILE /paci/ucb/ux453039/bhsf1.0000.out 02/23/2007 14:20:13 08/27/2007 14:53:48 FILE /users/ux454500/AIX.mpCC.DEBUG.ex 02/23/2007 14:20:13 02/28/2007 14:47:55 DIRECTORY /paci/ucb/ux453039/runs/bondi file3: DIRECTORY /paci/ucb/ux453039/. FILE /paci/ucb/ux453039/.ktb_ux453039 05/31/2006 17:52:04 09/01/2007 14:25:33 FILE /paci/ucb/ux453039/bhsf1.0000.out 02/23/2007 14:20:13 08/27/2007 14:53:48 FILE /users/ux454500/AIX.mpCC.DEBUG.ex 02/23/2007 14:20:13 02/28/2007 14:47:55 DIRECTORY /paci/ucb/ux453039/runs/bondi
and your effort on the code? Please read the forum rules, or for a simplified version; pytony's signature.
Also, I tried this with a file someone else posted here a couple days ago, it had a different format, but I feel the idea here is the same, the way I broke it down is just different because of the format:
File:
115 139-28-4313 1056.30
135 706-02-6945 -99.06
143 595-74-5767 4289.07
155 972-87-1379 3300.26
#codes
def extract_second(file):
col_2=[]
with open(file) as f:
for line in f:
chars=[]
line=line.split(' ')
for char in line:
if char not in ['',' ']:
chars.append(char)
col_2.append(chars[1])
return col_2
def extract_col(file,col):
columns=[]
with open(file) as f:
for line in f:
chars=[]
line=line.split(' ')
for char in line:
if char not in ['',' ']:
chars.append(char)
columns.append(chars[col])
return columns
#results
>>>extract_second('help.txt')
['139-28-4313', '706-02-6945', '595-74-5767', '972-87-1379']
>>>
>>>extract_col('help.txt',0)
['115', '135', '143', '155']
not sure if that helps at all, hope it does. And this worked fine with what I had of yours but it could be much cleaner, I was just messing around with it.
def extract_col(file,col):
column=[]
with open(file) as f:
for line in f:
chars=[]
line=line.split('\t')
for char in line:
if char not in ['',' ']:
chars.append(char)
chars=' '.join(chars)
chars=chars.split()
column.append(chars[col])
return column
output
extract_col('help2.txt',4)
['pph2_prob', '0.999', '0.999', '0.997']
In order to update the key values in the dictionary, doesn't they have to be in lists though? I not, i see no reason to change it.
That's kind of an oddly worded question, did you mean update the keys or update the values? If you're talking about values, no they don't HAVE to, but it would be much easier, and more practical to change, but here's an option with tuples:
def up_bal(tup,up):
tupe=tup[0:2]
tupe+=tup[2]+up,
return tupe
>>> a
('this', 'balance', 3.25)
>>> b=up_bal(a,5.23)
>>>
>>> b
('this', 'balance', 8.48)
Why wouldn't you just want the list??? Is it just a matter of printing? If not why not just return a list of integers??
>>> def renum(lis):
return [int(num) for num in lis]
>>> a=['1','2','3']
>>>
>>> b=renum(a)
>>> b
[1, 2, 3]
It's quite possible that is because people haven't used that or don't have much experience with it; it's not a matter of not wanting to help. Sometimes you just have to dig and dig to find you own answer, and I'm sure we'd be happy to see the result if you do.
What would i change if i wanted to store the values as lists instead of tuples?
well if you REALLY want to here's a hint: lis=[item for item in tup]
the context was a class inherited from the tkinter Frame class being used as a Toplevel, the problem I realized was that when I chose to destroy the frame,thinking of it as the window, really I was destroying the complete contents of that window. There were so many widgets in the frame that I didn't want to deal with grid_forget-ing all of them. but I did as woooee suggested "I don't know why I didn't think of it" and added a frame within it, destroyed it, and recreated it. Below is the tentative result, I haven't "prettied it up" yet with the geometry, button height, or grid locations. Note that it is the same window, I just took the screenshot twice to show the change when next is pressed.
Edit, apparently I can't change the button height for ttk style buttons...anybody done anything to get around that?
that is MUCH better, I changed the account balance in mine to a float just because I wasn't sure if you were going to change it. I broke mine down step by step because I like to "show my work" when helping out
def make_dic(file):
with open(file,'r') as f:
file=f.readlines()
dic={}
for line in file:
line=line.split(' ')
clean_tup=tuple()
for num in line:
if num!='':
clean_tup+=(num,)
dic[clean_tup[0]]=clean_tup[1]+' ',float(clean_tup[2].strip('\n'))
return dic
you could also make the key an int if you wanted, and I added that touch of whitespace just because it's more appealing to me. and you could always make them print pretty if you wanted by either manipulating the format or doing a funky little number like:
>>>dic=make_dic('accounts.txt')
>>>for account in dic:
display=''
display+=str(account)+':'
for data in dic[account]:
display+=' '+str(data)
print(display)
115: 139-28-4313 1056.3
143: 595-74-5767 4289.07
155: 972-87-1379 3300.26
135: 706-02-6945 -99.06
well when you call items, you get just that, all the items; keys and values. when you call keys you just get the keys and from there you could say something like:
query=input('Enter your search: ')
if query in phonebook.keys():
print(phonebook[query])
else:
print('invalid selection')
hurry and edit that! highlight it and hit the [code] button...
you need to use the code tags, note the (CODE) button when posting, hit that and paste your code in the tags it generates...
But isn't r the default option? Meaning if you don't type anything it will use r. The opening of files is not the issue here. Can anyone help with the sorting? Thanks.
it's bad practice to be implicit so I guess I wouldn't know. Have you looked up the source of the sorted() function or the sort method of the list class? I would imagine those would be pretty useful. And you need a parameter for that "Simplesort" function, it's not doing anything but returning.....nothing, otherwise.
Does anybody know how to clear all widgets; labels, buttons, etc. from a tkinter frame so that new ones may be put in their place? I've tried self.destroy() but that makes the frame unreachable, and self.grid_forget() followed by, "and without" self.grid() neither of these work, at least not as expected. any suggestions?
Among several other things, you're not telling python to do with that file your opening, you're not going to like the output, how about open(file,'r')...
Show us some effort, if you've been working on it for three days you must have some code, post it. And use the code tags when you do. Also read the forum rules.
Okay, I was able to look at your file and do it in about five minutes; think about what's getting into your dictionary that shouldn't, I'll show you mine; but I want to see a bit more effort, you're close, I guess I would say, be more selective about what makes it into your dictionary...
condition at line 12 quarantees that line 13 raises error, when you do enter the loop.
Yes, you essentially said, if this doesn't exist, add TO it, well that's quite impossible, if you told me to throw my recycling in the bin, but there was no bin I'd scream ERROR, so maybe you need to ADD it to the dictionary before we can add to it..."i.e. maybe you need to put a recycling bin in the trash area before I can add to it."
print line before joining, print line after stripping, then print line after splitting. It's annoying but it'll help you see what's happening.
ohhh tony and his one-liners ;-)
also, I'm not sure why you thought checking phonebook.items was the most prudent style...I hope you already know what's wrong with that choice; why not phonebook.keys()?