leegao 0 Newbie Poster

To be fair, top-down isn't a very descriptive name for the category of grammars.

If we're using http://java.sun.com/docs/books/jls/second_edition/html/syntax.doc.html without any modification, then this grammar is probably not suitable for LL(1).

The most obvious problem comes from Selector -> . x | . y | . z However, a LL(2) parser generator or one that does smart refactoring on the grammar (not possible with the action code however) will be able create a correct parser for this production rule.

More subtle issues includes:

1. The famous dangle else problem.
in the following production

Statement -> if ParExpression Statement [else Statement]

if we get rid of the extended syntax, (using the rules of left-factoring, in that A -> alpha [E] beta === A -> E' beta; E' -> epsilon | E), then we have
Statement -> if ParExpression Statement ELSE'
ELSE' -> epsilon | else Statement

since ELSE' is nullable, in order to fill the jump table for ELSE'[else], we must look at Follow(ELSE') = FOLLOW(Statement) which includes FIRST(ELSE') = {else}. Hence, we have a duplicity for the transition from ELSE' under the lookahead terminal of "else". In LL(1), this is an ambiguous production.

2. Expression3 -> Type Expression3
| Primary {Selector} {PostfixOp}

Since FIRST(Primary) U FIRST(Type) = {int,long,float,double,boolean}, Expression3 cannot predictively determine what action to take on encountering any of the primitive type tokens.

A few more ambiguities such as trying to determine how any …

leegao 0 Newbie Poster
# Very Loose translation, beware of the globals() and NEVER explicitly translate Perl to Python. See why below.

# Assumes that legs, the var referenced by legs, reference, ref, fields, fxall, merge_swap_legs, new_fk_ref, and logg exist
if legs in globals():
	legs = globals()[legs]
else:
	legs = locals()[legs]

if reference < len(legs): # if reference in legs if legs is a dictionary (if is a hash)
	logg("2nd leg of swapes: %s - merging"%ref)
	swap = merge_swap_legs(legs[ref], fields)
	ref = new_fk_ref(fxall,ref,swap)
else:
	legs[ref] = fields
	logg("1st leg of swap: %s"%ref)

"""
legs is a string
The variable referenced by legs is a list/dictionary
reference is an integer/string (if ^ is list/dictionary)
ref is of same type as reference
fields can be any object
fxall is arbitrary
Everything else are functions
"""

This however is a horrible coding style, post the complete code and I'll see if it can be easily built in python.

leegao 0 Newbie Poster

Sorry about the hasty post, I had to finish up a few last minute coursework. I'm sure there's a much more intuitive way of detecting null pointers and have not yet had the chance to explore further. I'll get back to you as soon as I find something.

leegao 0 Newbie Poster

Hi,

from ctypes import *
from see import see
import sys

class linknode(Structure):
    pass
linknode._fields_ = [
                ("nextNode", POINTER(linknode)),
                ("intData", c_int),
                ]
class linked_list():
    """ our own linked list based on ctypes """
    head_node = None
   
    def add(self, int_data):
        node_to_add = linknode(intData = c_int(int_data))
        if (self.head_node == None):
            self.head_node = node_to_add
        else:
            traverse_node = self.head_node
            node = traverse_node
            try:
                while node.nextNode.contents:
                    node = node.nextNode.contents
            except ValueError:
                node.nextNode = POINTER(linknode)(node_to_add)
            except:
                pass
    def __getitem__(self, n):
        node = self.head_node
        for i in range(n):
            node = node.nextNode.contents
        return node
                


if __name__ == "__main__":
    ll = linked_list()
    for i in range(10):
        print "Adding %s"%i
        ll.add(i)
    print ll[9].intData

Output:

Adding 0
Adding 1
Adding 2
Adding 3
Adding 4
Adding 5
Adding 6
Adding 7
Adding 8
Adding 9
9

ValueError catches the null pointer error

leegao 0 Newbie Poster
def get_list():
	return [raw_input("Please enter a string: ") for i in range(int(raw_input("Please enter the number of strings you want to input\n")))]

def shortest(lst):
	return min(lst, key = len)

def longest(lst):
	return max(lst, key = len)

def alpha(lst):
	return [e for e in lst if e.isalpha()]

if __name__ == "__main__":
	lst = get_list()
	lst.sort()
	print ", ".join(lst)
	print shortest(lst)
	print longest(lst)
	print ", ".join(alpha(lst))
leegao 0 Newbie Poster

Get the absolute path of the package and add it onto the python path

say abs_dir = '/root/downloads/package-name/'

Then at the start of your script, you need to do the following

from sys import path as PYTHONPATH
PYTHONPATH.append('/root/downloads/package-name')

If you're on windows, don't forget the escape the backslashes

(IE: when you see \, you need to change it to \\)

Alternatively you can just place it inside a folder that's already in the python path (IE: the python25 directory). If you're on Linux, try using whereis python25 and then place the package folder inside there, if you're on windows, just go with C:\Python25\

leegao 0 Newbie Poster

You do realize that C++ only supports ethernet (class 1) protocols and you must write your own wrapper to use higher level protocols (IP, TCP, + UDP) and generate your own packets.

leegao 0 Newbie Poster

a _name module is usually a swig/boost C/C++ library. Here try to see if there's a setup.py in the downloaded archive and use python setup.py build and python setup.py install.

leegao 0 Newbie Poster

try

import chilkat
leegao 0 Newbie Poster

Thanks for the advice, but the grep came up with nothing, and even after a few "find -name"s trying different keywords like pstats or pstats.* or *.py I'm still coming up empty..

I even went through the whole httpd.conf and i've found that there are a few virtualhosts but no pstats or anything similar...

I'm really at a loss as to where to go with this and lets just say documentation wasn't my predicessor's favourite task...

Well that seems to be it then. If the virtual host for pstats isn't found and your server runs on a apache backend then I guess the configuration that worked before has been over-written (Maybe by an upgrade of apache or through custom configurations). Anyways make sure to check all of the conf files for apache to see if you can find the pstats virtual host.

(Even if pstats is backproxied from another port, the virtualhost still must be configured first.)

Hope this helps.

leegao 0 Newbie Poster

And this is where apache's httpd.conf comes to the rescue.

cd /etc/httpd/conf
cat httpd.conf|grep pstats

This will give you the grep for the keyword pstats, and it will give you the static location of the files.

And now I'm also going to assume that you're running apache+mod_python as opposed to mod_wsgi
(Try grepping mod_python and mod_wsgi to see if you can find it)

If that still does not work then

cd /
find -name pstats

And these should be absolutely everything that you would need to do to find this dir.

After that: get the content of the (I'm guessing here) index.py file in that directory and paste it here so we can help you

leegao 0 Newbie Poster

scp is integrated with ssh so if you can find an openssh server for your platform, you should be in the clear. PS: It's not really recommended to use python for this as there are many steps required to complete this step via scp.

If you just need to transfer files over IP then yes, socket programming is your only option (PS: Everything from IP, TCP, UDP, etc all the way down to ETH All uses sockets as their interface. SCP and FTP both use sockets too).

The best way to implement this would be to create a stream socket (TCP) on a client-to-client base and do the following to manage the streaming:

1. Send the complete checksum (just use md5.hexdigest for this) followed by the length of the file
2. Start streaming the file one chunk at a time
3. On the server side, after then length of the stream == to the length sent by the number, do checksum comparison and close the socket.

leegao 0 Newbie Poster

Can you post what you have already done? I might be able to help you once I get a clearer picture of what's going on here.

leegao 0 Newbie Poster

Oh hey, this might help you, I wrote this helper class a while back while doing some work with excel and I decided to upload this onto github a few days ago.

http://github.com/leegao/pyXLSX/tree/master

Basic Usage:

from xlsx import workbook
def lastnums(t,n): return t[len(t)-n:len(t)]

Workbook = workbook("workbook.xlsx")
extractnums = ("12", "100")
sheet = Workbook.Sheets.Sheet1
for cell in sheet.keys():
	#Cell Name: 'Alpha''Num'
	for num in extractnums:
		if lastnums(cell, len(num)) == num:
			#Do whatever it is that you need to do
			pass
leegao 0 Newbie Poster

os.system doesn't emulate a shell environment so that might be the reason why. Try this

from subprocess import PIPE, Popen

build = Popen(("devenv.exe", "filename.sln", "/Build"), shell = True)

Alternatively put in the whole path of devenv.exe and see where that leads you.

leegao 0 Newbie Poster

That would return an error since the last 3 objects are arguments.

try

s = subprocess.Popen(("grep", "-w", "%s"%variable, Data.txt), stdout = subprocess.PIPE)
output = s.communicate()[0]
leegao 0 Newbie Poster

I've actually ported the python frontend up to 3.0.1, but I've never had experience with the python C API and apparently the C API had some major changes from 2.x to 3.x so I couldn't continue.

Here's my best shot: http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=14122&p=65820#p65812

leegao 0 Newbie Poster

well from the top of my head it should be

for line in file

instead of the plural form of line.

Is this basically how the gist of your script?

handle = open("file.file")
file = handle.readlines()
handle.close()
del handle

dict = {}
for line in file:
	#Here we just get the first, 3rd, and 4th character?
	match = (line[0], line[2], line[3])
	if match not in dict.keys():
		dict[match] = 0
	dict[match] += 1