Beat_Slayer 17 Posting Pro in Training

Your import concept mate is totally wrong. You should read a good python tutorial.

Back to the code, something like

self.image_list = []

def addImage(self, imageName):
        try:
            newImageData = {}
            im = Image.open(imageName)
            data = im.getdata()
            width, height = im.size
            self.image_list.append(imageName)
        except IOError:
            showerror( "File Error", "The selected file could either opened or converted." )
            return

        newImageData['im'] = im
        newImageData['data'] = data
        newImageData['width'] = width
        newImageData['height'] = height
        newImageData['id'] = -1
        newImageData['contours'] = []
        newImageData['dots'] = []
        newImageData['landmarks'] = []
        newImageData['linewidth'] = 1
        newImageData['linelength'] = 20
        newImageData['stack'] = self.getCurrentStack()
        self.imageInfo.append(newImageData)

You can then use the image_list something like...

for image in self.image_list:
    ...

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

First wrap your code with Code-tags. You can do it easilly by selecting your code and clicking the code button.

And that code is useless mate. I mean you to show the code you use to open them.

And imports are done at the beginning of the script and never inside a function.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You don't need to display them, if you maintain a list of the image objects open, you can easilly save them all in a nice loop.

Show a example of what you mean, I'll help you.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Only the print implementation.

You can do

from __future__ import print_function

and keep the 3.x print style.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

What you mean? Like clipboard access? Or a internal function?

Copy to variable and write the variable to the widget maybe?

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

doffing81, theres no need to hardcode the 5 deals.

def deal():
    """this function deals the cards individually to each hand"""
    for i in range(5):
        self.append(deck.pop(0))    #pop(0) grabs the first card/item in list
        p2.append(deck.pop(0))      #pop() would grab last...I believe
        p3.append(deck.pop(0))
        p4.append(deck.pop(0))

Cheers and Happy coding

doffing81 commented: Perfect +1
Beat_Slayer 17 Posting Pro in Training

Here it is. Now it works.

class Rectangle:

    def __init__(self, length = 1, width = 1):
        self.set_length(length)
        self.set_width(width)

    ##Setters to float
    def set_length(self, length):
        length = float(length)
        try:
            if 0.0 < length < 20.0:
                print "Value is in range.  You may continute."
                self._length = length
            else:
                raise ValueError
        except ValueError:
            print "Value must be between 0.0 and 20.0"

    def set_width(self, width):
        width = float(width)
        try:
            if 0.0 < width < 20.0:
                print "Value is in range.  You may continute."
                self._width = width
            else:
                raise ValueError
        except ValueError:
            print "Value must be between 0.0 and 20.0"
##Getters
    def get_length(self):
        return self._length

    def get_width(self):
        return self._width

##Get perimeter and area
    def perimeter(self):
        return 2 * self._length + 2 * self._width

    def area(self):
        return self._length * self._width

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Or

Hands.hasFlush()

for outside the class Hands, or

self.hasFlush()

if it's inside the class that defines hasFlush().

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Like this I believe...

#!/usr/bin/python
import socket
import subprocess

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
host = socket.gethostname()
port = 1234
sock.bind((host,port))

while True:
    command, addr = sock.recvfrom(1024)
    if len(command) > 0:
        print("Received ", command, " command from ", addr)
        exec_command = subprocess.Popen(command, stdout=subprocess.PIPE)
        print(exec_command.stdout.read())

sock.close()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

ask grade exam a
ask grade exam b
ask homework
90 = (needed*0.35) - (a*0.25) - (b*0.25) - (homework*0.15)

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Yeah, you need do read a litle bit before jumping into it, trying is good, but research also.

Some help

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Already had similar problems, we try to keep the names neat, but as it adds the script path to the syspath, it replaces the modules if we have files with the same name.

It can be cool depending of the situations. :D

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Mate change your script filename, it's replacing the module.

Your script named unittest.py, it's replacing the module file.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

???

Does yours outputs like this mate?

>>> import unittest
>>> dir (unittest)
['FunctionTestCase', 'TestCase', 'TestLoader', 'TestProgram', 'TestResult', 'TestSuite', 'TextTestRunner', '_CmpToKey', '_TextTestResult', '_WritelnDecorator', '__all__', '__author__', '__builtins__', '__doc__', '__email__', '__file__', '__metaclass__', '__name__', '__package__', '__unittest', '__version__', '_makeLoader', '_strclass', 'defaultTestLoader', 'findTestCases', 'getTestCaseNames', 'main', 'makeSuite', 'os', 'sys', 'time', 'traceback', 'types']
>>> print unittest.TestCase
<class 'unittest.TestCase'>

EDIT:

Mate change your script filename, it's replacing the module.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

The print, one place is enough.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Maybe if you search here you find something more.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You can use tkinter or Easygui, or downgrade do 2.x and use wxPython.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You should have all working with the ips you give, i believe it's firewall problem.

If you notice this forum has lots of sub-foruns, and evey one has a different category.

Python is a computer programmming language.

Maybe here, or here will be better to find your answer.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

For that function you use pyhton 3.x, or you do:

from __future__ import print_function

def main():
    f = open('lines.txt')
    for line in f:
        print(line, end = '')

if __name__ == "__main__": main()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

It relys on a bad configuration for sure.

If the printer is connected to the router on a valid network configuration, then it is on the same network as the computers, since that it should be a firewall problem.

It can also be a NAT problem.

Wich are the IPs? of the computer, router and printer?

Cheers and Happy printing :)

Beat_Slayer 17 Posting Pro in Training

It relys on a bad configuration for sure.

If the printer is connected to the router on a valid network configuration, then it is on the same network as the computers, since that it should be a firewall problem.

It can also be a NAT problem.

Wich are the IPs? of the computer, router and printer?

Cheers and Happy printing :)

Beat_Slayer 17 Posting Pro in Training

I believe with a GetCellValue(self, row, col) in a nice loop.

ncols = 7
row = 3
row = [self.GetCellValue(row, col) for col in range(ncols)]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Your router may be cofigured to only allow connections through ethernet cable and not wireless connections to the settings.

Apart that, this is the python forum, for python related questions.

Cheers and Happy coding.

Beat_Slayer 17 Posting Pro in Training

format
This parameter can be used instead of the fmt24hr and displaySeconds parameters, respectively; it provides a shorthand way to specify the time format you want. Accepted values are 'HHMMSS', 'HHMM', '24HHMMSS', and '24HHMM'. If the format is specified, the other two arguments will be ignored.
fmt24hr
If True, control will display time in 24 hour time format; if False, it will use 12 hour AM/PM format. SetValue() will adjust values accordingly for the control, based on the format specified. (This value is ignored if the format parameter is specified.)

You can do

self.EndingHour = masked.TimeCtrl(panel, -1, name='24 hour control', format = '24HHMM')

or

self.EndingHour = masked.TimeCtrl(panel, -1, name='24 hour control', fmt24hr = True)

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Some code???


Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

OFF-TOPIC

nod = lambda(x): len(str(x))

print nod(125125)

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

It does it now, but I'm not a regex expert, maybe they can make other way.

I can only see as searching with regex, catching the longest, then search for that group with the regex and ask the start.

words = ['cataaaaac', 'pooooloo']

for word in words:
    longest = 0
    letterlist = set(word)
    for char in letterlist:
        seq = sorted(re.findall('%s+' % char, word))[-1:]
        sequence = ''.join(seq)
        lenght = len(sequence)
        if lenght > longest:
            longest = lenght
            letters = sequence
    m = re.search(letters, word)
    print 'Word:', word
    print 'Most:', letters[0], 'with', len(letters), 'starting at index', m.start()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training
import re

words = ['cataaaaac', 'poolooo']

for word in words:
    longest = 0
    letterlist = set(word)
    for char in letterlist:
        for item in re.findall('%s+' % char, word):
            lenght = len(item)
            if lenght > longest:
                longest = lenght
                sequence = item
    print 'Word:', word
    print 'Most:', sequence[0], 'with', len(sequence), 'starting at index', word.index(sequence)

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

It does the work, but it's not regex.

words = ['cataaaaac', 'poolooo']

for word in words:
    rep = ''
    count = 0
    i = 0
    most = ''
    great = 0
    index = 0
    start = 0
    for char in word:
        if char == rep:
            count += 1
            if count > great:
                most = rep
                great = count
                index = start
        else:
            start = i
            rep = char
            count = 1
        i += 1
    print 'Word:', word
    print 'Most:', most, 'with', great, 'starting at index', index

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

As NOT wizards, we don't guess code solutions.


Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Like this mate.

import time
import subprocess

ip = '127.0.0.1'

def ping(ip):
    pinging = subprocess.Popen('ping -w 200 -n 1 ' + ip, stdout=subprocess.PIPE)
    if "0% loss" in pinging.stdout.read():
        return True

while 1:
    if ping(ip):
        subprocess.Popen('cmd')
        time.sleep(0.3)
    else:
        time.sleep(0.3)

Be aware, if you run it like this it will open a shell every 300 milisecs.

Cheers and Happy coding

s0ur commented: Really nice guy! :-) +0
Beat_Slayer 17 Posting Pro in Training

Popen.terminate()¶

Stop the child. On Posix OSs the method sends SIGTERM to the child. On Windows the Win32 API function TerminateProcess() is called to stop the child.

New in version 2.6.

Popen.kill()¶

Kills the child. On Posix OSs the function sends SIGKILL to the child. On Windows kill() is an alias for terminate().

Source

If you paste the code it will be more easy to help.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Why is he adding portability adding json???

Json is more dedicated to data interchange, pickle it's here used to store data to the file, not to send serialized data over network or to databases.

As the address book increases in datasize, I believe cPickle will make you feel the difference.

Cheers and Happy coding

Edit:

One reason to use cPickle???

import cPickle as pickle
import json
import time

def time_it(func):
    def wrapper(*arg):
        t1 = time.time()
        res = func(*arg)
        t2 = time.time()
        print '%s took %0.3f ms' % (func.func_name, (t2 - t1) * 1000.0)
        return res
    return wrapper

list1 = [1, 2, 3, 'string1', 'string2', 'string3',
         [23, 35, 46], {'somewhere': 1, 'elsewhere': 4}]

print list1

@time_it
def test_pickle():
    for run in range(100000):
        pickle.dumps(list1)

@time_it
def test_json():
    for run in range(100000):
        json.dumps(list1)

test_pickle()
test_json()

It's really fast.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I'll get you a start point.

try:
    import cPickle as pickle
except:
    import pickle


class address_book():

    def __init__(self):
        try:
            self.__db = open('addressbook.db', 'rb')
            self.__entries = pickle.load(self.__db)
            self.__db.close()
        except:
            self.__db = open('addressbook.db', 'wb')
            self.__entries = {}
            self.__db.close()

    def __update(self):
        self.__db = open('addressbook.db', 'wb')
        pickle.dump(self.__entries, self.__db, -1)
        self.__db.close()

    def add_entry(self, (name, number, email)):
        self.__entries[name] = {}
        self.__entries[name]['Telephone'] = number
        self.__entries[name]['E-mail'] = email
        self.__update()

    def show_data(self):
        for k, v in self.__entries.iteritems():
            print 'Name:', k
            for subk, subv in v.iteritems():
                print '%s: %s' % (subk, subv)
            print
        

app = address_book()

userdata = ('Paul', '00316123456789', 'something@somewhere.com')

app.add_entry(userdata)

app.show_data()

Implement the rest,

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Functions to add, remove and view entries to the address book, values stored in a pickled dictionary.

I'm eager to help, but I want to see some code effort from you.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

And like this?

for item in pl[section]:
    if item.find('dashboard-tile') != -1:
        print "Dashboard" # dont need other values because there are none
        print '\t'.join((item['tile-data']['file-label'], item['tile-data']['file-data']['_CFURLString'], item['tile-data']['dashboard-tile'], section, plist_path))
    else:
        print '\t'.join((item['tile-data']['file-label'], item['tile-data']['file-data']['_CFURLString'], section, plist_path))

If you post your present code, I can do some clean up.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Yeah, I've no OS X experience.

Why don't you paste here the full plist? It would get easier.

For the correction, maybe:

for item in pl[section]:
    try:
      	if item.find('dashboard-tile') != -1:
       	    print "Dashboard" # dont need other values because there are none
        else:
            print '\t'.join((item['tile-data']['file-label'], item['tile-data']['file-data']['_CFURLString'], section, plist_path))

EDIT: Look what I've just found. plistlib — Generate and parse Mac OS X .plist files


Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Work it, and post when you get stuck.

from random import choice

first_list = []
second_list = []

for item in open('sampleconnection.txt').readlines():
    first, second = item.split('\t')
    first_list.append(first)
    second_list.append(second.strip('\n'))

for i in range(len(first_list)):
    choices_list = range(len(first_list) - 1)
    choices_list.remove(i)
    print first_list[i], second_list[choice(choices_list)]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Litle help...

for item in pl[section]:
    if item.has_key('dashboard-tile'):
        try:
            print '\t'.join((item['tile-data']['file-label'], item['tile-data']['file-data']['_CFURLString'], item['tile-data']['dashboard-tile'], section, plist_path))

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

And like this?

import nltk
import os
import smtplib
import time

from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import encoders

from nltk.corpus import gutenberg
from random import choice


triggerSentence = raw_input("Please enter the trigger sentence: ")#get input str

lastLongestStr = ""
listOfSents = gutenberg.sents('austen-emma.txt') #all sentences of gutenberg are assigned -list of list format-
listOfWords = gutenberg.words('austen-emma.txt')# all words in gutenberg books -list format-

class gmail():
    
    def __init__(self):
        self.recipient = "xxxxxxx@hotmail.com"
        self.gmail_user = "asdassdsaadssd"
        self.gmail_pwd = "asdasdasasdasasd"
        self.subject = "assadasdasasdass"

    def create_mail(self, message):
        self.themail = MIMEMultipart()
        self.themail['Subject'] = self.subject
        self.themail['From'] = self.gmail_user
        self.themail['To'] = self.recipient
        self.themail.attach(MIMEText(message)) 
	
    def send_mail():
        smtpserver = smtplib.SMTP("smtp.gmail.com",587)
        smtpserver.ehlo()
        smtpserver.starttls()
        smtpserver.login(self.gmail_user, self.gmail_pwd)
        print "Connection established."
        smtpserver.sendmail(self.gmail_user, self.recipient, self.themail.as_string())
        print "Your mail has been sent."
        smtpserver.close()


while triggerSentence:

    longestLength = 0
    longestString = ""
    longestLen2 = 0
    longestStr2 = ""
    #run the loop so long as there is a trigger sentence

    sets = []
    split_str = triggerSentence.split()#split the sentence into words
        
    #code to find the longest word in the trigger sentence input
    for piece in split_str:
        if len(piece) > longestLength:
            longestString = piece
            longestLength = len(piece)

    if longestString == lastLongestStr:
       longestString = sorted(split_str, key=len)[-2]
       print longestString + " second longest!"

       if longestString == lastLongestStr:
          longestString = sorted(split_str, key=len)[-3]
          print longestString + " third longest!"
    
    print longestString + " is now the longest"
    print "\n"

    #code to get the sentences containing the longest word, then selecting
    #random one of these sentences that are longer than 40 characters

    for sentence1 in listOfSents: …
Beat_Slayer 17 Posting Pro in Training

Your code is very messy, very distorted, but if you copy your line 18 to line 25 it will work.

Anyway I recommend some clean up.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

What you want Tcll, the conversion of the case?

How are you reading the values?

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Line 1 of your convert.py says 'on win32'?

I guess that's not valid python code, and thats why the import is failing.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I don't get it????

Whats the question? You create a picture image object RGB 600 by 600, but you write no data to it.

And you do something with a ImageDraw object but I can't see what also.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

What happens when you run this?

What's the console output?

Sugestions??
Put dnaml on the path and run the script from the OutputFiles folder to avoid all those nasty paths.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You must use the 'SetCellValue(self, row, col, s)' attrivute of the grid.

Make a loop, read row, iterate trough items, and insert the data on the cells.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I never said to compare it with if..elif..else.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training
list1 = []

for y in range(50):
    for x in range(50):
        list1.append((x, y))

print list1

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I think it's easy as making a case and a for loop and testing them.


Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Like:

os.system('program.exe | argument')

Cheers and Happy coding.