Beat_Slayer 17 Posting Pro in Training

So you can't read C++, and want to convert some C++ files to Python?

How about leaking the C++ files so we can help you?

Meanwhile, i'll google for tools. ;)

Beat_Slayer 17 Posting Pro in Training

How about this?

class Word_Counter():

    def __init__(self):
        self.count = {}

    def add_string(self, s):
        word_list = s.split(' ')
        self.add_list(word_list)

    def add_list(self, wl):
        for item in wl:
            if self.count.has_key(item):
                self.count[item] += 1
            else:
                self.count[item] = 1

    def add_mapper(self, ml):
        for item in ml:
            if self.count.has_key(item[0]):
                self.count[item[0]] += item[1]
            else:
                self.count[item[0]] = item[1]
    


str1 = 'the quick brown fox jumps over the lazy dog'

d = Word_Counter()

d.add_string(str1)

print d.count

"""
{'brown': 1, 'lazy': 1, 'over': 1, 'fox': 1, 'dog': 1, 'quick': 1, 'the': 2, 'jumps': 1}
"""

list1 = ('the', 'quick', 'blue', 'cat', 'jumps', 'over', 'the', 'lazy', 'turtle') 

d.add_list(list1)

print d.count

"""
{'blue': 1, 'brown': 1, 'lazy': 2, 'turtle': 1, 'over': 2, 'fox': 1, 'dog': 1, 'cat': 1, 'quick': 2, 'the': 4, 'jumps': 2}
"""

map1 = [('the', 1), ('quick', 1), ('brown', 1), ('fox', 1), ('jumped', 1), ('over', 1), ('the', 1), ('lazy', 1), ('grey', 1), ('dogs', 1)]

d.add_mapper(map1)

print d.count

"""
{'blue': 1, 'brown': 2, 'lazy': 3, 'turtle': 1, 'grey': 1, 'jumped': 1, 'over': 3, 'fox': 2, 'dog': 1, 'cat': 1, 'dogs': 1, 'quick': 3, 'the': 6, 'jumps': 2}
"""
Beat_Slayer 17 Posting Pro in Training

I believe it's a simple path problem, since they are common on win.

Try to create a shortcut for the application, setting the 'start in' option to that folder.

Beat_Slayer 17 Posting Pro in Training

I believe this is what you want.

f_in = open('xxx.txt').readlines()[:12959]
f_output= open('output.txt', 'w')

for item in f_in[:5]:
    f_output.write(item)

for item in f_in[5:]:
        firstdata, seconddata = item.split(' ')[:2]
        f_output.write('%s, %s\n' % (firstdata, seconddata))
'%s %s\n' % (firstdata, seconddata)

The '%' places the variables, here firstdata and seconddata, formated as strings due to the 's', in the output string. The '\n' adds a linebreak.

Beat_Slayer 17 Posting Pro in Training
Beat_Slayer 17 Posting Pro in Training

Like this?

f_in = open('xxx.txt').readlines()[:12960]
f_output= open('output.txt', 'w')

for line in f_in:
        firstdata, seconddata = line.split(' ')[:2]
        f_output.write('%s, %s\n' % (firstdata, seconddata))
Beat_Slayer 17 Posting Pro in Training

If you provide a sample file, it can get easier.

But this should do it, if youre csv files are not encoded, the module it's not needed.

f_in = open('xxx.txt').readlines()
f_output= open('output.txt', 'w')

for line in f_in:
    if not line.count('STOP'):
        firstdata, seconddata = line.split('/')[:2]
        f_output.write('%s, %s\n' % (firstdata, seconddata))
    else:
        print line
Beat_Slayer 17 Posting Pro in Training

How about you post some file and some code, so we can toy with also. ;)


Happy coding!

Gribouillis commented: well said ! +4
Beat_Slayer 17 Posting Pro in Training

It's like this you must do it on your terminal window like this:

python /Users/Home/Desktop/Programs/test2.py

or just by the scipt name if you add the shebang:

#!/usr/bin/python

to the first line of your script.

Happy coding!

Cheers

Beat_Slayer 17 Posting Pro in Training

I think this should give some insight, if I'm understanding what you are trying to do.

def merge_dic(merged_dic, wordlist):
    for item in wordlist:
        if merged_dic.has_key(item):
            merged_dic[item] += 1
        else:
            merged_dic[item] = 1

file1 = 'this is a dummy sample file for example as sample'
file2 = 'this is another dummy sample file also created for example with \
some samples repeated for example'

list1 = file1.split(' ')
list2 = file2.split(' ')

all_count = {}
file_lists = []
file_lists.extend(list1)
file_lists.extend(list2)

merge_dic(all_count, file_lists)

print 'all_count =', all_count

file_uniques = {}
file_lists = []                 # Converting lists to sets it's the fastest and
file_lists.extend(set(list1))   # simplest way that I know of eliminating
file_lists.extend(set(list2))   # duplicates on a list, when position doesn't mather

merge_dic(file_uniques, file_lists)

print 'file_uniques =', file_uniques

Happy coding!

Beat_Slayer 17 Posting Pro in Training

It can be just me, but it seems something is wrong!

Can you explain a little further.

You want to know the words that exist in the two files, is that it?

Or do you want to count the ocurrences in each file?

Beat_Slayer 17 Posting Pro in Training

Simple script for image transparency.

Someone asked one some time ago, and i had other but for a different system, and decided to write a Python/PIL version.

The value of the color used as transparent is the value of the pixel at position (0, 0).

You can adjust tolerance value.

Happy coding!

Beat_Slayer 17 Posting Pro in Training
Beat_Slayer 17 Posting Pro in Training

Look here!

A little search helps. ;)

Happy coding!

Beat_Slayer 17 Posting Pro in Training

Your welcome.

Happy to help!

You can close the thread marking it as solved.

Cheers, and happy coding!!!

Beat_Slayer 17 Posting Pro in Training

I get the same results without mecanize.

I believe the problem is somewhere in the password or username.

Beat_Slayer 17 Posting Pro in Training
f = open('filename.rc')
old_rc = f.readlines()
f.close()

host = 'PARTYHOST'
new_ip = '127.0.0.1'
f = open('filename.rc', 'w')
for i in range(len(old_rc)):
    if old_rc[i].find(host) != -1:
        f.write('%s %s\n' % (host, new_ip)) #You should check the newline
    else:
        f.write(old_rc[i])
f.close()
Beat_Slayer 17 Posting Pro in Training

This should give you some insight!

import csv

for row in csv.reader(open('timeline1.csv', 'r')):
    match = None
    for item in row:
        if item.find('.ie/') != -1:
            match = True
    if match:
        print 'Highlighted ->>', row
    else:
        print row

I'm not a tk programmer, but:

def searchfilt(self):
    f = open("timeline1.csv", "r") 
    reader = csv.reader(f) 
    text = enterbox(msg='Please choose a highlighter search term', title='Highlighter ', default='', strip=True)
    lines = []
    i = -1
    self.listbox2.delete(0, tk.END)
    for i, line in enumerate(reader):
        for words in line:
            if words.find(text) != -1:
                self.listbox2.itemconfig(i, bg='red', fg='white')
        self.listbox2.insert(tk.END, line)
Beat_Slayer 17 Posting Pro in Training

Can you try this, substituting the user and pass?

import urllib

params = urllib.urlencode({'user': '0123456789', 'password': 'password', 'submit.x': '0', 'submit.y': '0'})
site = 'http://portal.hu.edu.jo:7777/huregister/index.jsp'
webpage = urllib.urlopen(site, params)
results = webpage.read()
webpage.close()
print results

and changing line 4 to:

site = 'http://portal.hu.edu.jo:7777/huregister/sbmt_index.jsp'
Beat_Slayer 17 Posting Pro in Training

Can you try this?

body = {'user': user, 'pswd': passo, 'submit.x': '39', 'submit.y': '7'}
Beat_Slayer 17 Posting Pro in Training

I presume your using python 3, because the sample file works.

You can try like this bellow, or go for a aproach without the module as tonyvj said.

import csv

d = {}

for row in csv.reader(open('sample.csv')):
    first, second = [value.strip() for value in row[0].split('\t')]
    if d.has_key(first.strip()):
        d[first].append(second)
    else:
        d[first] = [second] 

f = open('output.txt', 'w')
for k, v in d.iteritems():
    print k, v
    f.write('%s %s\n' %(k, v))
f.close()

Cheers.

Happy coding!

Beat_Slayer 17 Posting Pro in Training

Can you post a real sample CSV?

Beat_Slayer 17 Posting Pro in Training

Does pyexcelerator doesn't work?

Wich system you are running, and can you post a sample xls?

Wich error message the converter from pyexcelerator gives?

Beat_Slayer 17 Posting Pro in Training
import csv

d = {}

for row in csv.reader(open('sample.csv', "rb")):
    first, second = row[0].split('\t')
    if d.has_key(first.strip()):
        d[first.strip()] += [second.strip()]
    else:
        d[first.strip()] = [second.strip()] 

for k, v in d.iteritems():
    print k, v

Cheers, and Happy coding.

Beat_Slayer 17 Posting Pro in Training

You have the pyexcelerator module, with a conversion script in the examples folder.

Happy coding.

Beat_Slayer 17 Posting Pro in Training

Some insights, and some more!

Hope it helps!

Happy coding!

Beat_Slayer 17 Posting Pro in Training

Do you have some code?

Can you post a sample csv file?

Happy codding!

Beat_Slayer 17 Posting Pro in Training

Like this?

if(empty($veh_img) AND empty($disk_img)){
    $galpic="image.gif";
}else{
    $galpic="$disk_img";
}
Beat_Slayer 17 Posting Pro in Training
def squareEach(nums):
    squares=[]
    for number in nums:
        squares += [number * number]
    return squares
Beat_Slayer 17 Posting Pro in Training
if(!strcmp($row['dtFirstContactSt'], '0000-00-00') AND !strcmp($row['dtMarketingSt'], '0000-00-00')) {
echo "<td width='156'>" . "&nbsp </td>";
} else {
echo "<td bgcolor=FF0000 width='156'>" .$row['dtFirstContactSt']. "</td>";
}
Beat_Slayer 17 Posting Pro in Training

Use pprint, or some tabbed printing, so it looks like a table.

Beat_Slayer 17 Posting Pro in Training
Beat_Slayer 17 Posting Pro in Training
from random import randint

color = (randint(0, 255), randint(0, 255), randint(0, 255))
Beat_Slayer 17 Posting Pro in Training

Then the image with the higher coordinate in x, it's the image in wich the sum of the loading x and the size in x is greater.

Beat_Slayer 17 Posting Pro in Training

Maybe like this.

str1 = "Hello Monty Python!"
str2 = str1.replace('M', 'Spam')
str3 = str2.replace('P', 'Spam')
def print_str(str1, str2, str3):
    print(str1)
    print(str2)
    print(str3)
print_str()

or

str1 = "Hello Monty Python!"
str2 = str1.replace('M', 'Spam')
str3 = str2.replace('P', 'Spam')
print('%s\n%s\n%s' % (str1, str2, str3))
Beat_Slayer 17 Posting Pro in Training

Can you explain a little further?

Have you loaded the image?

Beat_Slayer 17 Posting Pro in Training

You can do a select first to see if it exits, and delete thereafter if exists, or give error message if it doesn't.

Beat_Slayer 17 Posting Pro in Training

I guess it is

windowSurface.blit(pi, 25, 25)

or

windowSurface.blit(pi, (25, 25))

but i never used pygame.

Beat_Slayer 17 Posting Pro in Training

You need to find a way to simulate a pressed key.

I have a key simulator somewhere.

I'll search and say something when I get home.

Beat_Slayer 17 Posting Pro in Training

Can you show, or at lest say wich type of server you implemented?

You can use the sockets as files, passing and reading from them the coordinates.

Beat_Slayer 17 Posting Pro in Training

Click on "Start", select "Run" and type "command"!

Beat_Slayer 17 Posting Pro in Training

Have you tried like this?

r = csv.reader(open('v20100515.csv', 'rb'))

EDIT: Sorry i began the reply and went eat some sandwich, finnished when I came, and there were already all this ones posted, but I didn't saw them.

Beat_Slayer 17 Posting Pro in Training

Example command for a script file 'protein.py' in directory 'D:\scripts\protein\', the executable file will be created in 'D:\scripts\protein\exe'.

cxfreeze d:\scripts\protein\protein.py --target-dir d:\scripts\protein\exe

Demonstration on Windows XP with Python 2.6.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Beat_Slayer>cd c:\python26\scripts

C:\Python26\Scripts>cxfreeze d:\scripts\protein\protein.py --target-dir d:\scripts\protein\exe
creating directory d:\scripts\protein\exe
copying C:\Python26\lib\site-packages\cx_Freeze\bases\Console.exe -> d:\scripts\protein\exe\protein.exe
copying C:\WINDOWS\system32\python26.dll -> d:\scripts\protein\exe\python26.dll
writing zip file d:\scripts\protein\exe\protein.exe

  Name                      File
  ----                      ----
m StringIO
m UserDict
m __builtin__
m __future__
m __main__                  d:\scripts\protein\protein.py
m _abcoll
m _bisect
m _codecs
m _codecs_cn
m _codecs_hk
m _codecs_iso2022
m _codecs_jp
m _codecs_kr
m _codecs_tw
m _collections
m _functools
m _heapq
m _locale
m _multibytecodec
m _random
m _sre
m _strptime
m _struct
m _subprocess
m _threading_local
m _warnings
m abc
m array
m base64
m bdb
m binascii
m bisect
m bz2                       C:\Python26\DLLs\bz2.pyd
m cPickle
m cStringIO
m calendar
m cmd
m codecs
m collections
m copy
m copy_reg
m cx_Freeze__init__         C:\Python26\lib\site-packages\cx_Freeze\initscripts\
Console.py
m datetime
m difflib
m dis
m doctest
m dummy_thread
P encodings
m encodings.aliases
m encodings.ascii
m encodings.base64_codec
m encodings.big5
m encodings.big5hkscs
m encodings.bz2_codec
m encodings.charmap
m encodings.cp037
m encodings.cp1006
m encodings.cp1026
m encodings.cp1140
m encodings.cp1250
m encodings.cp1251
m encodings.cp1252
m encodings.cp1253
m encodings.cp1254
m encodings.cp1255
m encodings.cp1256
m encodings.cp1257
m encodings.cp1258
m encodings.cp424
m encodings.cp437
m encodings.cp500
m encodings.cp737
m encodings.cp775
m encodings.cp850
m encodings.cp852
m encodings.cp855
m encodings.cp856
m encodings.cp857
m encodings.cp860
m encodings.cp861
m encodings.cp862
m encodings.cp863
m encodings.cp864
m encodings.cp865
m encodings.cp866
m encodings.cp869
m encodings.cp874
m encodings.cp875 …
Beat_Slayer 17 Posting Pro in Training

Sometihing is wrong, since urllib2 should give you the same source code for the page.

Beat_Slayer 17 Posting Pro in Training

I think your line 28 should have the login address page, and not the page you are trying to read later.

Beat_Slayer 17 Posting Pro in Training

Do a litle search on the forum, theres a lot of CSV search and modify examples.

Write a tryout, and post the results, with input files and desired output.

Happy coding

Beat_Slayer 17 Posting Pro in Training

Just take the break out, and it will read all lines, indicating all errored ones.

Beat_Slayer 17 Posting Pro in Training

The concept is the same as in this Tech B snippet.

Give it a try,

Happy coding.

Beat_Slayer 17 Posting Pro in Training

Don't make the things more difficult.

1 - install cx_freeze.

2 - Open windows command shell, and navigate to your python install dir, then to scripts inside that dir.

3 - Type cxfreeze plus your path and script name, something like this:

cxfreeze d:\scripts\hello.py

4 - It will create a dir called dist with the files ready.

And you are done.

No need to do a setup script, or any modification to your script.

Beat_Slayer 17 Posting Pro in Training

The working file, is the file wich you are processing.

The one that you create or open, and read or write to it.