Beat_Slayer 17 Posting Pro in Training
Beat_Slayer 17 Posting Pro in Training
def __init__(self, title='Console Application Menu', size=(80, 25), border='#', log_title='Log Output:'):
 
"""The class initialization takes as optional arguments:
- title: title text of the menu
- size: the size in characteres of the console window menu
- border: character to be printed as border for the menu and dialogs
- log_title: title text of the log window"""

You change the

border='#'

to

border='='

in there. If you read the comments it gets pretty clear.

Hope I helped. Cheers and Happy Coding

P.S.: I'm back. =D

Beat_Slayer 17 Posting Pro in Training

I'm new ot twisted, but thats all I was able by now to extract as peer info.

But, your implementation does'nt seem right to me.

I'll take a look into twisted, I think I'll write something, meanwhile...

from twisted.protocols.basic import LineOnlyReceiver
from twisted.internet  import reactor
from twisted.internet.protocol import ServerFactory
import time


class ChatConnection(LineOnlyReceiver):

    def __init__(self):
        self.hostlist = []
        self.hostname = ""
        self.master = ""

    def sendLine(self, line):
        self.transport.write(line + '\n')

    def print_time(self):
        return time.strftime("[%H:%M] ", time.localtime(time.time()))

    def name(self):
        self.nick = self.transport.getPeer()
        return ' '.join([str(item) for item in self.nick])
    
    def connectionMade(self):
        print  self.print_time() + "New connection from " + self.name()
    
        if self.name == self.hostname:
            self.master = self.transport.getPeer().host
        else:
            self.factory.IDandIP[self.name] = self.transport.getPeer().host
            self.hostlist.append(self.name())

        def connectionLost(self, reason):
            print self.print_time() + "Connection lost by", self.name()
            del self.factory.IDandIP[self.name]
            self.hostlist.remove(self.name())

          
        def lineReceived(self, line):
        
            if line == "/list":
                self.sendLine(self.print_time() + "Online users: \n\t" + str(self.hostlist))
    
            if line[:6] == "zombie":
                self.master.sendLine(line[:6])
            else:
                ID = line.split(" : ")[0]
        
                if ID in self.hostlist:
                      self.IDandIP[ID].sendLine(line)
        
                 
class Chat(ServerFactory):
     
    protocol = ChatConnection
    
    def __init__(self):
        
        self.IDandIP = {}

print "Waiting connection from clients..."
main = Chat()
reactor.listenTCP(8000, main)
reactor.run()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I can't see the problem, and it's working good.

Maybe IDLE? Maybe version of the pygame you use?

Cheers and Happy coding

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

The usage is

SetGridCursor(self, row, col)

, so why collumn -1 on your code mate?

self.SpeciesGrid.SetGridCursor(ind, -1)

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training
class SpeciesGrid(wx.Frame):

    self.EnglishNameList = ['Great Tit','Marsh Tit','Coal Tot','Crested Tit']

Your code defines EnglishNameList as a attribute of the SpeciesGrid class, so you must change the

self.EnglishNameList

on the SearchDlg class by something like

SpeciesGrid.EnglishNameList

.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Sorry mate, now I got it! :D

I made consfusion, the country I'm in now has a provider named 'Telnet', and I just stupidlly thought you were talking about it. I'm very sorry.

I'll take a look.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

1 - I mean that if you use subprocess, you don't have to edit or prepare the scripts, you can just load them as they are and redirect the output, with logging the scripts must be prepared to use the module and make the output.

2 - Yes you can make the two, it's a mather of implementation.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You can create a script, wich loads your scripts with subprocess, and then you can redirect the output, like this you won't need to adjust the scripts.

More than that, you can write a module or use logging as told, but for that you must adjust your acripts to.

Cheers and Happy coding


Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Add '\n' in each write.

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

Wait, this is the server code, right?

How do you connect to it?

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

You are write, just not implementing good.

Because as you say, if you don't escape the '.' it will match any simbol, and so...

re.search('[0-9][0-9][0-9].','1234atxt')

will work. But as you 'escaped' it using the '\' it matchs the '.'.

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

It seems to work here...

import re

print re.findall('[0-9][0-9][0-9]\.', '1234_.txt')
print
print re.findall('[0-9][0-9][0-9]\.', '1234.txt')

Can you explain what's not working.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

The distance between vectors, presuming you have vector A and B with two coordinates x and y, is:

sqrt(((Ax - Bx) ** 2) + ((Ay - By) ** 2))
Beat_Slayer 17 Posting Pro in Training

The from_points function pass the values to the __init__ by the cls variable, and not the other way around.

When you call 'AB = Vector2.from_points(A, B)' it will pass the 'A' and 'B' tuples to the 'from_points' function that will calculate and pass then the result to the class __init__ function.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You want all the output in text file, or only the error output?

Wich OS? Are you using GUI?

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

This should be faster.

lines = [line for line in tx.readlines(2000000)]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I've installed twisted mate.

Do you have client code? Can you post it, or PM it to me?

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

And like this?

def name(self):
    connector = self.transport.connector
    return connector.getDestination()

I'll install twisted to take a look.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Something like this...

f_in = open('file.csv')
lines = f_in.readlines()[1:]
fields = [item for item in lines.split(',')]
selected = []
for field in fields:
    selected.append((field[4], field[6]))

It will need adjusting...

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Wheres your code?

Wich methods have you tryed to?

Wich are the errors?

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

@staticmethod returns a static method for function.

@classmethod returns a class method for function.

The classmethod is called with the 'cls' argument as first argument and it represents the class.

It's called when you create a class object and will serve as constructor for the class.

At line 13 it will pass the data from the 'from_points()' function to the class.

And when the class object 'AB' is called to be printed the '__str__' function is called.

Hope that helps...

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

How about showing some code??

Anyway the getDestination() should retrieve you the hostname.

Try something like...

peer = self.transport.getPeer()
nick = peer.getDestination()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Something like...

self.transport.getDestination()

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.

Cheers and Happy codings

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

You have urllib2 also, or you can try with the Beautiful Soup.

Cheers and happy coding

Beat_Slayer 17 Posting Pro in Training

The error message, and not the error type, were of great help.

And a code usage sample also

And wheres line 95?

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You can also tweak it to don't show the process window.

If on windows it would get like this.

exec_command = subprocess.Popen(command, stdout=subprocess.PIPE, creationflags=0x08000000)

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

what are you trying to do? A folder creation?

os.makedirs('c:\\foo\\bar')

Look here.
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

Thanks for the enlightement mate.

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

Faster...

from itertools import combinations
import time

list1 = [18, 20, 53, 86, 91, 3, 13, 88, 4, 31, 21, 66, 66, 93, 14, 2, 67, 56, 46, 2]
int1 = 816

duplicates = True

print 'List:', ', '.join([str(i) for i in list1])

if not duplicates:
    list1 = list(set(list1))

list1 = [item for item in sorted(list1) if (item + min(list1)) <= int1]

print 'Clean List:', ', '.join([str(i) for i in list1])

def min_list(x, mlist):
    m, rest = divmod(x, max(mlist))
    if rest:
        return m + 1
    else:
        return m

def max_list(x, mlist):
    m, rest = divmod(x, min(mlist))
    if not rest:
        return m - 1
    else:
        return m

def subsets(nlist, wanted, min_list_size, max_list_size):
    for s in range(min_list_size, max_list_size + 1):
        for item in combinations(nlist, s):
            if sum(item) == int1:
                yield item

t1 = time.clock()
valid_sums = []
for valid in subsets(list1, int1, min_list(int1, list1), max_list(int1, list1)):
    valid_sums.append(valid)
t2 = time.clock()

print 'Subsets took %0.3f ms' % ((t2 - t1) * 1000.0)
print '%s is the sum of %s subsets' % (int1, len(valid_sums))
for sums in valid_sums:
    print '%s is the sum of %s' % (int1, ', '.join([str(i) for i in sums]))

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

My version was written taking in count that no duplicates were used. Line 9 makes it pretty clear.

I can do a quick mod do accept duplicates.

I'll be back :D

Cheers and Happy coding

EDIT:

from itertools import combinations
import time

list1 = [18, 20, 53, 86, 91, 3, 13, 88, 4, 31, 21, 66, 66, 93, 14, 2, 67, 56, 46, 2]
int1 = 816

duplicates = True

print 'List:', ', '.join([str(i) for i in list1])

if not duplicates:
    list1 = list(set(list1))

list1 = [item for item in sorted(list1) if (item + min(list1)) <= int1]

print 'Clean List:', ', '.join([str(i) for i in list1])

subsets_list = []

def min_list(x, mlist):
    m, rest = divmod(x, max(mlist))
    if rest:
        return m + 1
    else:
        return m

def max_list(x, mlist):
    m, rest = divmod(x, min(mlist))
    if not rest:
        return m - 1
    else:
        return m

def subsets(nlist, wanted, min_list_size, max_list_size):
    for s in range(min_list_size, max_list_size + 1):
        if not duplicates:
            rlist = [item for item in nlist if item >= (wanted / len(nlist))]
            nlist = rlist
        for item in combinations(nlist, s):
            subsets_list.append(item)

t1 = time.clock()
subsets(list1, int1, min_list(int1, list1), max_list(int1, list1))
t2 = time.clock()
print 'Subsets took %0.3f ms to calculate %s subsets' % ((t2 - t1) * 1000.0, len(subsets_list))

valid_sums = [item for item in subsets_list if sum(item) == int1]

print '%s is the sum of %s subsets' % (int1, len(valid_sums))
for sums in valid_sums:
    print '%s is the sum of %s' % (int1, ', …
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

The if statements are no repeated, theres one if for each sprite.

The if of line 42 moves the second sprite (x2) every 5 frames, or being said every 5 movements of the first sprite (x1)

The frame counter is incremented on line 52.

Cheers and Happy coding