Index in a list

2012-10-17 Thread Anatoli Hristov
Hello, I'm trying to index a text in a list as I'm importing a log file and each line is a list. What I'm trying to do is find the right line which contains the text User : and take the username right after the text "User :", but the list.index("(User :") is indexing only if all the text matching

Re: Index in a list

2012-10-17 Thread Anatoli Hristov
Thanks a lot this solved my issue:) Regards Anatoli On Wed, Oct 17, 2012 at 12:23 PM, Chris Angelico wrote: > On Wed, Oct 17, 2012 at 9:10 PM, Anatoli Hristov wrote: >> Hello, >> >> I'm trying to index a text in a list as I'm importing a log file and >>

Re: Change computername

2012-10-17 Thread Anatoli Hristov
Thank you, I will test this, will keep you posted. Anatoli On Wed, Oct 17, 2012 at 7:47 PM, Ian Kelly wrote: > On Wed, Oct 17, 2012 at 8:07 AM, Anatoli Hristov wrote: >> Hello, >> >> Can you please help me out how can I change the computername of >> windows XP

Re: Change computername

2012-10-18 Thread Anatoli Hristov
It does not work the result is "0" And I don't find any documentation about it :( On Thu, Oct 18, 2012 at 8:41 AM, Anatoli Hristov wrote: > Thank you, > > I will test this, will keep you posted. > > Anatoli > > On Wed, Oct 17, 2012 at 7:47 PM, Ian Kelly wr

program loaded in memory

2012-10-21 Thread Anatoli Hristov
Hello, I need an advice about a small script I run 24/24 7/7. It's a script converted to EXE using py2exe and this script takes - grows 30kb RAM on each loop which means that for 10hours it grows up with 180mb memory. is there something I can do ? >From the ini file I'm loading only the URL and t

Re: program loaded in memory

2012-10-21 Thread Anatoli Hristov
grows up with 30kb. And I'm using Python 2.7 on windows 7 Thanks On 22 Oct 2012, at 02:21, Dave Angel wrote: > On 10/21/2012 08:02 PM, Anatoli Hristov wrote: >> Hello, >> >> I need an advice about a small script I run 24/24 7/7. >> >> It's a script co

Re: Compare list entry from csv files

2012-11-26 Thread Anatoli Hristov
n for it. Thanks On Mon, Nov 26, 2012 at 11:08 PM, Dave Angel wrote: > On 11/26/2012 04:08 PM, Anatoli Hristov wrote: >> Hello, >> >> I'm trying to complete a namebook CSV file with missing phone numbers >> which are in another CSV file. >> the namebook file

Re: Compare list entry from csv files

2012-11-27 Thread Anatoli Hristov
On Tue, Nov 27, 2012 at 4:23 AM, Dave Angel wrote: > On 11/26/2012 05:27 PM, Anatoli Hristov wrote: >> I understand, but in my case I have for sure the field "Name" in the >> second file that contains at least the first or the last name on it... >> So probably it s

Re: Compare list entry from csv files

2012-11-27 Thread Anatoli Hristov
On Tue, Nov 27, 2012 at 4:05 PM, Neil Cerutti wrote: > On 2012-11-27, Anatoli Hristov wrote: >> Thanks for your help. I will do my best for the forum :) >> >> I advanced a little bit with the algorithm and at least I can >> now extract and compare the fields :) For my

Re: Compare list entry from csv files

2012-11-29 Thread Anatoli Hristov
On Tue, Nov 27, 2012 at 9:41 PM, Neil Cerutti wrote: > On 2012-11-27, Anatoli Hristov wrote: >> Thank you all for the help, but I figured that out and the >> program now works perfect. I would appreciate if you have some >> notes about my script as I'm noob :) Here is

Re: Compare list entry from csv files

2012-11-30 Thread Anatoli Hristov
> Can you print ex_phone first. You are opening the files in text mode > so I wonder if the line endings are causing you to read and extra > "line" in between. Can you try reading the csv as "rb" instead of > "rt"? Yes I did this: use the global list PHONELIST and opening the CSV in binary - it wo

Re: Compare list entry from csv files

2012-11-30 Thread Anatoli Hristov
> As I said before, process both files into lists, one that you treat as > constant (and therefore capitalized) and the other containing the data > you intend to modify. > > It'd be much cleaner if you did all that input file parsing stuff in one > function, returning only the lists. Call it just

CSV out of range

2012-12-04 Thread Anatoli Hristov
Hello, I tried to read a CSV file with 3 products in it and index it into a list using file = open("ShopPrices.csv", "rbU") reader = csv.reader(file, delimiter=";") mylist = [] for x in reader: mylist.append(x) The problem comes when I try to index the SKU array and the field is empty

Re: CSV out of range

2012-12-04 Thread Anatoli Hristov
On Tue, Dec 4, 2012 at 12:31 PM, Thomas Bach wrote: > Hi there, > > Please be a bit more precise… > > On Tue, Dec 04, 2012 at 12:00:05PM +0100, Anatoli Hristov wrote: >> >> The problem comes when I try to index the SKU array and the field is >> empty > &

Re: CSV out of range

2012-12-04 Thread Anatoli Hristov
The issue is now solved I did: for x in mylist: try: sku.append(x[4]) except IndexError: pass Thank you for your help Anatoli -- http://mail.python.org/mailman/listinfo/python-list

Re: CSV out of range

2012-12-04 Thread Anatoli Hristov
On Tue, Dec 4, 2012 at 2:58 PM, Neil Cerutti wrote: > On 2012-12-04, Anatoli Hristov wrote: >> The issue is now solved I did: >> >> for x in mylist: >> try: >> sku.append(x[4]) >> except IndexError: >> pass >> >> Th

Confused compare function :)

2012-12-05 Thread Anatoli Hristov
Hi all, I'm confused again with a compare update function. The problem is that my function does not work at all and I don't get it where it comes from. in my DB I have total of 754 products. when I run the function is says: Total updated: 754 Total not found with in the distributor: 747 I just do

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
On Thu, Dec 6, 2012 at 1:31 AM, Steven D'Aprano wrote: > On Wed, 05 Dec 2012 23:50:49 +0100, Anatoli Hristov wrote: > > >> def Change_price(): > > Misleading function name. What price does it change? > > >> total = 0 >> tnf = 0 > > "t

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
Guys I'm still confusing my script is working better, but not enough. I did a logfile to see which products are not found anymore in the CSV and I found some that are present but python says they are not ?? Here is the product in the CSV: MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
On Thu, Dec 6, 2012 at 3:22 PM, Anatoli Hristov wrote: > Guys I'm still confusing my script is working better, but not enough. > I did a logfile to see which products are not found anymore in the CSV > and I found some that are present but python says they are not ?? > > He

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
>> No one have an idea ? >> >> Thanks >> > > Basically because your code is crap. Others have already suggested > refactoring your code to make it easier to follow. Thank you Mark for your notes. I changed the name of the variables as was suggested before. I know my code should be crappy, but at

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
>> Here is the product in the CSV: >> MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide >> 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41; This one is still not found and it is in the CSV file - I just don't get it why ! >> if len(db_s

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
Here is the product in the CSV: MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41; > [snip] > It's not saying that it's not found, it's saying that it wasn't updated > because: You are right

Re: Confused compare function :)

2012-12-06 Thread Anatoli Hristov
> gmane.comp.python.general: > >> But basically, the code seems to run a pair of nested for-loops: >> >> for SKU in database: >> for SKU in csv file: >> if the two SKUs match: >> compare their prices and update the database >> > OUCH... > > I'm presuming the

Re: Confused compare function :)

2012-12-07 Thread Anatoli Hristov
>> Calling it 'found' is misleading, because it's True only if it updated. >> If it found a match but didn't update, 'found' will still be False. >> Using a loop within a loop like this could be the cause of your >> problem. It's certainly not the most efficient way of doing it. > > I will keep you

MySQLdb insert HTML code error

2012-12-10 Thread Anatoli Hristov
Hi all, I'm facing an issue inserting an html code into the DB, it comes out with a syntax error but I face it only when I have html code. Could help me escape the error somehow ? Here is my code def InsertSpecsDB(product_id, spec, lang, name): db = MySQLdb.connect("localhost","getit","openc

Re: MySQLdb insert HTML code error

2012-12-10 Thread Anatoli Hristov
> As much use as a chocolate teapot, all you've given is a function/method > definition. No indication of your OS, Python version, calling code, what > you expect to happen, what actually happened, apart from that your request > for assistance is perfect. Usually I'd be able to help but sadly my

Re: MySQLdb insert HTML code error

2012-12-10 Thread Anatoli Hristov
On Tue, Dec 11, 2012 at 1:29 AM, Anatoli Hristov wrote: >> As much use as a chocolate teapot, all you've given is a function/method >> definition. No indication of your OS, Python version, calling code, what >> you expect to happen, what actually happened, apart from t

Re: MySQLdb insert HTML code error

2012-12-10 Thread Anatoli Hristov
> You're using a parametrised query (which is good :-)), but you've included > quotes around the placeholders. There's no need to do that. They'll be > quoted automatically when necessary: > > sql = "INSERT INTO product_description (product_id, language_id, name, > description) VALUES (%s,%s,%s,%s)

Re: MySQLdb insert HTML code error

2012-12-10 Thread Anatoli Hristov
> >First thing -- DON'T put quotes around the %s place-holders... The > whole purpose of using the parameterized .execute() is to let the > database adapter properly escape the parameters before putting them into > the SQL (since MySQL didn't have prepared statements before v5, it was > produci

Re: MySQLdb insert HTML code error

2012-12-11 Thread Anatoli Hristov
> SSCCE starts with "Short". The HTML you unloaded into that email > hardly qualifies. > > When you're trying to figure out a problem that appears to happen only > when you have X and not when you have Y, see what the smallest example > data for X and Y are that continue to exhibit the difference.

MySQLdb compare lower

2012-12-11 Thread Anatoli Hristov
Hello guys, Excuse me for the noob question, but is there a way to compare a field in mysql as lower() somehow? I have a situation where I compare the SKU in my DB and there are some SKU that are with lowercase and some with uppercase, how can I solve this in your opinion ? def Update_SQL(price,

Re: MySQLdb compare lower

2012-12-11 Thread Anatoli Hristov
> I think this will work: > > sql = 'UPDATE product SET price=%s WHERE LOWER(sku)=%s' > cursor.execute(sql, (price, sku.lower()) > Thanks John, this works, I was about to make double check with lower and upper, but this saves me :) Thanks a lot. -- http://mail.python.org/mailman/listinfo/

Re: Unicode

2012-12-17 Thread Anatoli Hristov
> What happens when you do use UTF-8? This is the result when I encode the string: " étroits, en utilisant un portable extrêmement puissant—le plus petit et le plus léger des HP EliteBook pleine puissance—avec un écran de diagonale 31,75 cm (12,5 pouces), idéal pour le professionnel ultra-

Re: Unicode

2012-12-17 Thread Anatoli Hristov
> What's your terminal's encoding? That looks like you have a CP-1252 > terminal trying to output UTF-8 text. Thanks for your answer, I tried in my terminal and it gives this as an output: LANG=en_US LC_CTYPE="en_US" LC_NUMERIC="en_US" LC_TIME="en_US" LC_COLLATE="en_US" LC_MONETARY="en_US" LC_MES

Re: Unicode

2012-12-17 Thread Anatoli Hristov
> if you only see encoding problems on printing results to your > terminal, its settings or unicode capability might be the cause, > however, if you also get badly encoding items in the database, you are > likely using an inappropriate encoding in some step. I get badly encoding into my DB > you

Re: Unicode

2012-12-17 Thread Anatoli Hristov
> Hi, > I don't know, what the product ID would look like, for this page, but > assuming, the catalog pages are also utf-8 encoded as well as the > error page I get, it should work ok; cf.: You are right, I get it work on Windows too, but not in Linux. I changed the codec of linux, but still I don'

Re: Unicode

2012-12-17 Thread Anatoli Hristov
> src.decode() is creating a unicode string. The error is not happening > there. But when print is used with a unicode string, it has to encode > the data. And for whatever reason, yours is using latin-1, and you have > a character in there which is not in the latin-1 encoding. I fixed the print

Re: Unicode

2012-12-17 Thread Anatoli Hristov
> I fixed the print, I changed the setting of the terminal and also on > the sshconfig, so now when I print I'm able to print out without > problems, but when I tried to run the script I've made it gives me > again the same error : > ""Unexpected error: exceptions.UnicodeEncodeError > """ > Maybe I

Re: Unicode

2012-12-17 Thread Anatoli Hristov
> I doubted that 2.7 would make any difference. Yeah this complicated my life even more, all my import functions was gone - took me 2h to fix all :) and it does not solved my issue:) > > 1. What does your "terminal' expect. (For all I know you're using > TeraTermPro as a terminal, which doesn't su

Re: Unicode

2012-12-17 Thread Anatoli Hristov
>> Just realize that once you start using 'ignore' you're going to also >> ignore discrepancies that are real. For example, maybe your terminal is >> actual something other than either latin-1 or utf-8. > > If you need to see such discrepancies, you can do > > print src.decode("utf-8").encode("lati

Help writelines

2012-02-03 Thread Anatoli Hristov
Hi everyone, I`m totaly new in python and trying to figure out - how to write a list to a file with a newline at the end of each object. I tried alot of combinations :) like: users = ['toli','didi'] fob=open('c:/Python27/Toli/username','w') fob.writelines(users) + '%s\N' fob.close() or fob.writel

Re: Help writelines

2012-02-03 Thread Anatoli Hristov
it cheers Anatoli On Fri, Feb 3, 2012 at 9:56 PM, Dave Angel wrote: > On 02/03/2012 03:27 PM, Anatoli Hristov wrote: > >> Hi everyone, >> >> I`m totaly new in python and trying to figure out - how to write a list to >> a file with a newline at the end of each

Help about dictionary append

2012-02-05 Thread Anatoli Hristov
Hi there, I`m again confused and its the dictionary. As dictionary does not support append I create a variable list with dictionary key values and want to add new values to it and then copy it again to the dictionary as I dont know other methods. mydict = {'Name':('Name1','Name2','Name3'),'Tel':(

Re: Help about dictionary append

2012-02-05 Thread Anatoli Hristov
Thanks Chris, It works fine, I see it will take time till I understand all the syntax :( A.H On Sun, Feb 5, 2012 at 4:20 PM, Chris Angelico wrote: > On Mon, Feb 6, 2012 at 2:13 AM, Anatoli Hristov wrote: > > Hi there, > > > > I`m again confused and its the dictionary. A

Advise of programming one of my first programs

2012-03-26 Thread Anatoli Hristov
Hi guys just wanted to share one of my first programs. Could you please tell me, do I use a right logic ? It works fine what I wanted to do, but is it writen in the right way? My next step is to make it write the changes of the dictionary on the file :) ## DB tbook = {'goodie':['Christian','Van E

Re: Advise of programming one of my first programs

2012-03-27 Thread Anatoli Hristov
Thank you Ramit for your advice`s. I`m reading a book ( Learning Python, Second Edition ) by Mark Lutz and David Ascher and now I just finished the Basic Function lesson :) I will keep in mind what you have advised me, but will implement it later when I have more experience with the book, because I

Re: Advise of programming one of my first programs

2012-03-27 Thread Anatoli Hristov
> > This was difficult, now I feel more confused it works, but I`m sure its > not the way you wanted :) > The use of eval is dangerous if you are not *completely* sure what is >> being passed in. Try using pickle instead: >> http://docs.python.org/release/2.5.2/lib/pickle-example.html > > I`m s

Re: Advise of programming one of my first programs

2012-03-27 Thread Anatoli Hristov
Thanks, but I`m still far from for dose details I thing:) Regards Anatoli On Tue, Mar 27, 2012 at 5:53 PM, Tim Chase wrote: > On 03/27/12 10:32, Prasad, Ramit wrote: > >> fileread = open('myfile.txt','r') >>> tbook = eval(fileread.read()) >>> fileread.close() >>> >> >> The use of eval is danger

Re: Advise of programming one of my first programs

2012-03-28 Thread Anatoli Hristov
> You are correct it is not. :) You code is overly complex making it harder > to understand. Try and reduce the problem to the least number of tasks you > need. > >From the Zen of Python, "Simple is better than complex." It is a good > programming > mentality. Complex is better than complicated.

Re: RE: Advise of programming one of my first programs

2012-03-28 Thread Anatoli Hristov
> > Um, at least by my understanding, the use of Pickle is also dangerous if > > you > > > are not completely sure what is being passed in: > > > > Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this > > code: > > > > from pickle import loads > > loads("c__builtin__\neval\n(c_

Re: Advise of programming one of my first programs

2012-03-30 Thread Anatoli Hristov
> > ** > > Absolutely! Too bad your version would be considered the more > “complicated” version ;) > I`m sure about that, but I`am also sure that every beginner passed true that way. > > > ** ** > > >With the main navigation menu I will only have the option to select a > nickname and when a

Re: Advise of programming one of my first programs

2012-03-31 Thread Anatoli Hristov
Ramit, This seems to be more logic now "I hope" :) # import ast fname = 0 lname = 1 country = 2 city = 3 tel = 4 notes = 5 ## Read data from file def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = ast.literal_eval(loa

Run once while loop

2012-04-03 Thread Anatoli Hristov
Hi, I'm trying to do a while loop with condition of time if time is 12:00:00 print text, but for this one second the text is printed at least 50 times, how can I print only once? Thank Anatoli -- http://mail.python.org/mailman/listinfo/python-list

Re: Run once while loop

2012-04-03 Thread Anatoli Hristov
On 03 Apr 2012, at 22:45, Ian Kelly wrote: > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov wrote: >> Hi, >> >> I'm trying to do a while loop with condition of time if time is >> 12:00:00 print text, but for this one second the text is printed at >> lea

Re: Run once while loop

2012-04-04 Thread Anatoli Hristov
; On Tue, 3 Apr 2012 23:00:22 +0200 > Anatoli Hristov wrote: > > > On 03 Apr 2012, at 22:45, Ian Kelly wrote: > > > > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov > wrote: > > >> Hi, > > >> > > >> I'm trying to do a while