Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
TasteMyHouse
Dec 21, 2006

ToxicFrog posted:

It's a windows thing, not a python thing - in general it'll accept / and \ interchangeably in paths. Very handy.

this is not always the case, as I recently discovered in the C++ thread...


To be 100% sure, use os.path.join() and os.sep.

Adbot
ADBOT LOVES YOU

ToxicFrog
Apr 26, 2008


TasteMyHouse posted:

this is not always the case, as I recently discovered in the C++ thread...


To be 100% sure, use os.path.join() and os.sep.

Ok, replace "in general" with "when not using the command line". / is also conventionally used as the flag character for windows and DOS command line tools, so some of those tools will see the / in argv, interpret it as starting a flag, and freak out. The problem is with the tool - os.mkdir("Downloads/dogs") in python still works.

Bodhi Tea
Oct 2, 2006

seconds are secular, moments are mine, self is illusion, music's divine.
I'm trying to learn some web dev stuff with Flask.

My goal is to have an autocomplete box such that when something is typed, the database is searched and the results are returned in JSON format.

But I've come across the issue described here: http://flask.pocoo.org/docs/security/
where Flask will only allow objects to be top-level elements. So my question is, how do I return multiple results in JSON format for the autocomplete?

Sorry if this doesn't make a whole lot of sense.

Haystack
Jan 23, 2005





Couldn't you just jsonify a list as a member value?

code:
def get_current_users():
    users = ["Paul", "Henry", "Richard"]
    return jsonify(users=users)
Which should output the following JSON, if I'm understanding Flask's API correctly
code:

{
    "users": ["Paul", "Henry", "Richard"]
}

Haystack fucked around with this message at 19:35 on Sep 10, 2011

Bodhi Tea
Oct 2, 2006

seconds are secular, moments are mine, self is illusion, music's divine.

Haystack posted:

Couldn't you just jsonify a list as a member value?

code:
def get_current_users():
    users = ["Paul", "Henry", "Richard"]
    return jsonify(users=users)
Which should output the following JSON, if I'm understanding Flask's API correctly
code:

{
    "users": ["Paul", "Henry", "Richard"]
}
I think the situation I'm in is different.

From this page in the Flask docs, I'm using the query_db function
code:
def query_db(query, args=(), one=False):
    cur = g.db.execute(query, args)
    rv = [dict((cur.description[idx][0], value)
               for idx, value in enumerate(row)) for row in cur.fetchall()]
    return (rv[0] if rv else None) if one else rv
It returns a list of dictionaries, where each dictionary corresponds to a row in the result set, and the keys in each dictionary are columns of the result set.

So say I do a search for "John" as the name, I use the query_db function to get a list of dicts where the name matches "John". I want to return the entire result set in JSON format, but I'm thinking that requires that each result will should be a JSON array:
code:
{
{name:"John Smith",email="blah@blah"},
{name:"John Carpenter",email="blah@blah"},
{name:"John Williamson",email="blah@blah"}}
But from what I understand, I can't do this with Flask because it only allows top-level objects as the result of jsonify?

Again, I'm sorry if this makes no sense, I'm still trying to understand how this all works.

Haystack
Jan 23, 2005





Right. So you could get your list of dicts from query_db, then pass it as a keyword argument to jsonify.
code:
johns = query_db("some SQL looking for Johns")
output = jsonify(results=johns)
Which should create JSON like so:

code:
{
    "results": [ {name:"John Smith",email="blah@blah"},
                 {name:"John Carpenter",email="blah@blah"},
                 {name:"John Williamson",email="blah@blah"}
               ]
}
Which your clientside code could access and iterate over.

Bodhi Tea
Oct 2, 2006

seconds are secular, moments are mine, self is illusion, music's divine.

Haystack posted:

Right. So you could get your list of dicts from query_db, then pass it as a keyword argument to jsonify.
code:
johns = query_db("some SQL looking for Johns")
output = jsonify(results=johns)
Which should create JSON like so:

code:
{
    "results": [ {name:"John Smith",email="blah@blah"},
                 {name:"John Carpenter",email="blah@blah"},
                 {name:"John Williamson",email="blah@blah"}
               ]
}
Which your clientside code could access and iterate over.

Thank you!

PainBreak
Jun 9, 2001
In python, with a 12 digit date string like YYYYMMDDHHMM how would you subtract 1 hour?

For example, 201109010000 would be Midnight of August 1st EDT. I want to make it CDT, so I need to subtract an hour, and have it return 201108312300.

I'm not a python guy at all...I just want to modify some code to switch it to CDT.

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

PainBreak posted:

In python, with a 12 digit date string like YYYYMMDDHHMM how would you subtract 1 hour?

For example, 201109010000 would be Midnight of August 1st EDT. I want to make it CDT, so I need to subtract an hour, and have it return 201108312300.

I'm not a python guy at all...I just want to modify some code to switch it to CDT.

Import it into a datetime object (http://docs.python.org/library/datetime.html), modify it, then turn it back into a string.

Yay
Aug 4, 2007

PainBreak posted:

In python, with a 12 digit date string like YYYYMMDDHHMM how would you subtract 1 hour?
To expand on BeefOfAges post;
code:
from datetime import datetime, timedelta
new_dt = datetime.strptime(your_val, '%Y%m%d%H%M') - timedelta(hours=1)
print(new_dt.strftime('%Y%m%d%H%M'))
or something, ought to work.

Cojawfee
May 31, 2006
I think the US is dumb for not using Celsius
Is there a simple way to just make unicode() work in windows? I'm making a text adventure thing and in order to display my map I need unicode. This works just fine in linux, but windows won't let me use the unicode function.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Cojawfee posted:

Is there a simple way to just make unicode() work in windows? I'm making a text adventure thing and in order to display my map I need unicode. This works just fine in linux, but windows won't let me use the unicode function.
IMO, unicode(some_str) and str(some_unicode) are fundamentally broken in Python 2.x. You always want to use .decode() and .encode() instead, which will do what you want.

For example, if your bytestring is in utf8, say my_bytes.decode('utf8') and it'll work on all platforms.

There's the special form unicode(some_str, 'utf8') which is equivalent, but this makes the decode implicit and thus I discourage it.

Zombywuf
Mar 29, 2008

Cojawfee posted:

Is there a simple way to just make unicode() work in windows? I'm making a text adventure thing and in order to display my map I need unicode. This works just fine in linux, but windows won't let me use the unicode function.

If unicode() is not working then your original string is not in ASCII. You need to find out what charset it is in. I don't know how you'd do this on windows I'm afraid. UTF-16 might be a good guess, windows loves the UTF-16.

Innocent Bystander
May 8, 2007
Born in the LOLbarn.
Hey, I developed a rather large scale Python app a while back in Python 2.6 and I'm wondering if its time to port to Python 3.x. Do you guys see a huge advantage in it? Something tells me Python 2.x isn't going to leave anytime particularly soon (CentOS/RHEL 6 are shipping with 2.6). Thinks it would be worthwhile to setup upgrade all RHEL/CentOS distros to 3.x (obviously as an opt install) and upgrade the code to 3.x?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Innocent Bystander posted:

Hey, I developed a rather large scale Python app a while back in Python 2.6 and I'm wondering if its time to port to Python 3.x. Do you guys see a huge advantage in it? Something tells me Python 2.x isn't going to leave anytime particularly soon (CentOS/RHEL 6 are shipping with 2.6). Thinks it would be worthwhile to setup upgrade all RHEL/CentOS distros to 3.x (obviously as an opt install) and upgrade the code to 3.x?

That's just a waste of time, at least wait until some major distros start shipping Python 3 as the standard python install.

duck monster
Dec 15, 2004

Python 3.0 has long had that whole IP6v thing going on. Everyone agrees its a good idea, but nobody seems game to be the first to take the plunge and go all out.

angrytech
Jun 26, 2009

MEAT TREAT posted:

That's just a waste of time, at least wait until some major distros start shipping Python 3 as the standard python install.

By that argument, you might as well do it now if you have the time.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

MEAT TREAT posted:

That's just a waste of time, at least wait until some major distros start shipping Python 3 as the standard python install.

Arch does. Gentoo ... did at some point, maybe: I distinctly remember doing a fresh install of Gentoo in a VM in the recent past and being very confused when catalyst (the Gentoo release engineering tool, written in Python) didn't work. The system interpreter was Python 3, which Portage was okay with. I haven't done a fresh install of Gentoo in a decent amount of time, so I don't know if the stage3 tarballs still use Python 3 by default. It may have been transient or even a bug. Arch and Gentoo aren't RHEL or Debian, but some major distros do let you skip Python 2 entirely.


Anyway, run 2to3.py on your codebase and see how much work you have to do afterward. If you wrote your code with a lot of the new stuff in 2.6, you might just have to remove some extra calls to list() that aren't necessary but that 2to3.py isn't smart enough to skip.

Captain Capacitor
Jan 21, 2008

The code you say?
^^^ I can't help but think that his "vision" was the Diefenbunker

Lysidas posted:

Distrooooooos

I'm pretty sure that Debian/Ubuntu will be sticking with 2 for the time being. A lot of Ubuntu's package managing stuff (and OpenStack, which will be integrated in Ocelot) are all not yet ported to 3.

Cojawfee
May 31, 2006
I think the US is dumb for not using Celsius
Turns out I had 3.2 installed for some reason and not 2.7, everything works fine now.

Profane Obituary!
May 19, 2009

This Motherfucker is Dead

duck monster posted:

Python 3.0 has long had that whole IP6v thing going on. Everyone agrees its a good idea, but nobody seems game to be the first to take the plunge and go all out.

A lot of "core" packages are now available for python 3. Django is probably going to be the next big package getting ported to Python 3, which will probably get a lot more people to care.

PresidentCamacho
Sep 9, 2009
I'm trying to learn a bit more about python and picked up Tkinter as it's pretty easy. My problem is that I cannot figure out how to insert images(gifs in this case) into a listbox. Here is what I'm working with right now:

code:
import Tkinter

root = Tkinter.Tk()
L = Tkinter.Listbox(selectmode=Tkinter.SINGLE)

gif = Tkinter.PhotoImage(file="temp.gif")
L.insert(Tkinter.END, gif)

L.pack()

root.mainloop()

Sylink
Apr 17, 2004

What is the ideal way to read the memory of a Windows process and maybe change it in python?

Any recommended modules?

Mostly I just want to read the memory, something a la Cheat Engine, so I can use for other purposes.

tripwire
Nov 19, 2004

        ghost flow

Sylink posted:

What is the ideal way to read the memory of a Windows process and maybe change it in python?

Any recommended modules?

Mostly I just want to read the memory, something a la Cheat Engine, so I can use for other purposes.

I remember seeing a python tool for memory searching for use in cheating at games a while back. I googled it again and I think I found a different one altogether, at this page: http://www.forbiddencheats.net/forum/showthread.php?8185-Python-Memory-Scanning-Software

You would need pywin32 and something called "my_debugger_defines", which some additional googling tells me is a set of constants relating to windows debugging stuff.

Use at your own risk :)

crm
Oct 24, 2004

Ok, I'm looking into getting into some python web programming.

I've been writing Java code for a long long time and was looking for some advice.

I realize the OP has a lot of this information in it, but it's fairly broad.

So:

1) What's the recommended windows development environment / ide / setup?

2) What's the easiest / most popular application stack? Basically the python version of LAMP. I've seen cherrypy and stuff like that, I'm just not especially familiar with it.

3) Is there a good overview web frameworks? I know Django is pretty popular, but my understanding is that it's pretty heavy weight.

4) Any good "starting point" tutorials out there? I'm a veteran coder, so just looking for something that can give me an overview of the assorted technology (both python and web framework/app stack)

Thanks!

Haystack
Jan 23, 2005





crm posted:

1) What's the recommended windows development environment / ide / setup?

It's not free, but people seem to like Pycharm. Or, since you come from a Java background, you might like Eclipse with Pydev. I personally use Aptana, which is built on top of Eclipse and uses pydev.

quote:

2) What's the easiest / most popular application stack? Basically the python version of LAMP. I've seen cherrypy and stuff like that, I'm just not especially familiar with it.

It depends on your framework. Linux is obviously the OS of choice. Popular WSGI servers include Apache + mod_wsgi and nginx + uWSGI. Alternately, lots of frameworks are bundled with fully functional servers (Pyramid, Flask, Bottle, probably others). Database choice can virtually anything. SQLalchemy makes database integration pretty trivial (if you aren't using Django, which has its own ORM). No-SQL solutions like MongoDB, Redis, and ZODB are also popular.

quote:

3) Is there a good overview web frameworks? I know Django is pretty popular, but my understanding is that it's pretty heavy weight.

Django is a full stack framework, meaning that it makes some choices for you about things like database integration, sessions, etc. It's got a huge community and tons of extensions, though.

On the other end of the scale, there are micro-frameworks like Flask or Bottle. They let you get up and running with an incredibly small amount of effort, but might not be suitable for large, complicated applications.

In between, there's Pyramid, which offers more in the way of centralized integration than microframeworks, while allowing for more flexibility than Django.

Haystack fucked around with this message at 00:11 on Sep 18, 2011

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

Pycharm is free for open source projects!

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?
A personal license for PyCharm is half price until the end of September.

The Gnome
Sep 8, 2011

by R. Guyovich
Hey, I am using the osl.py downloaded code at http://www.scipy.org/Cookbook/OLS [the download is in the first paragraph with the bold OLS] but I need to understand rather than using random data for the ols function to do a mulilinear regression. I have a specific dependent variable y, and three explanatory variables. Everytime I try to put in my variables in place of the random variables it gives me an error

code:
TypeError: this constructor takes no arguments.
code:
[from __future__ import division
from scipy import c_, ones, dot, stats, diff
from scipy.linalg import inv, solve, det
from numpy import log, pi, sqrt, square, diagonal
from numpy.random import randn, seed
import time

class ols:
"""
Author: Vincent Nijs (+ ?)

Email: v-nijs at kellogg.northwestern.edu

Last Modified: Mon Jan 15 17:56:17 CST 2007

Dependencies: See import statement at the top of this file

Doc: Class for multi-variate regression using OLS

Input:
     dependent variable
    y_varnm = string with the variable label for y
    x = independent variables, note that a constant is added by default
    x_varnm = string or list of variable labels for the independent variables

Output:
    There are no values returned by the class. Summary provides printed output.
    All other measures can be accessed as follows:

    Step 1: Create an OLS instance by passing data to the class

        m = ols(y,x,y_varnm = 'y',x_varnm = ['x1','x2','x3','x4'])

    Step 2: Get specific metrics

        To print the coefficients: 
            >>> print m.b
        To print the coefficients p-values: 
            >>> print m.p

"""

y = [29.4, 29.9, 31.4, 32.8, 33.6, 34.6, 35.5, 36.3, 37.2, 37.8, 38.5, 38.8,
            38.6, 38.8, 39, 39.7, 40.6, 41.3, 42.5, 43.9, 44.9, 45.3, 45.8, 46.5,
            77.1, 48.2, 48.8, 50.5, 51, 51.3, 50.7, 50.7, 50.6, 50.7, 50.6, 50.7]
        #tuition
x1 = [376, 407, 438, 432, 433, 479, 512, 543, 583, 635, 714, 798, 891,
            971, 1045, 1106, 1218, 1285, 1356, 1454, 1624, 1782, 1942, 2057, 2179,
            2271, 2360, 2506, 2562, 2700, 2903, 3319, 3629, 3874, 4102, 4291]
        #research and development
x2 = [28740.00, 30952.00, 33359.00, 35671.00, 39435.00, 43338.00, 48719.00, 55379.00, 63224.00,
            72292.00, 80748.00, 89950.00, 102244.00, 114671.00, 120249.00, 126360.00, 133881.00, 141891.00,
            151993.00, 160876.00, 165350.00, 165730.00, 169207.00, 183625.00, 197346.00, 212152.00, 226402.00, 
            267298.00, 277366.00, 276022.00, 288324.00, 299201.00, 322104.00, 347048.00, 372535.00,
            397629.00]
        #one/none parents 
x3 = [11610, 12143, 12486, 13015, 13028, 13327, 14074, 14094, 14458, 14878, 15610, 15649,
            15584, 16326, 16379, 16923, 17237, 17088, 17634, 18435, 19327, 19712, 21424, 21978,
            22684, 22597, 22735, 22217, 22214, 22655, 23098, 23602, 24013, 24003, 21593, 22319]


def __init__(self,y,x1,y_varnm = 'y',x_varnm = ''):
"""
Initializing the ols class. 
"""
self.y = y
#self.x1 = c_[ones(x1.shape[0]),x1]
self.y_varnm = y_varnm
if not isinstance(x_varnm,list): 
    self.x_varnm = ['const'] + list(x_varnm)
else:
    self.x_varnm = ['const'] + x_varnm

# Estimate model using OLS
self.estimate()

def estimate(self):

# estimating coefficients, and basic stats
self.inv_xx = inv(dot(self.x.T,self.x))
xy = dot(self.x.T,self.y)
self.b = dot(self.inv_xx,xy)                    # estimate coefficients

self.nobs = self.y.shape[0]                     # number of observations
self.ncoef = self.x.shape[1]                    # number of coef.
self.df_e = self.nobs - self.ncoef              # degrees of freedom, error 
self.df_r = self.ncoef - 1                      # degrees of freedom, regression 

self.e = self.y - dot(self.x,self.b)            # residuals
self.sse = dot(self.e,self.e)/self.df_e         # SSE
self.se = sqrt(diagonal(self.sse*self.inv_xx))  # coef. standard errors
self.t = self.b / self.se                       # coef. t-statistics
self.p = (1-stats.t.cdf(abs(self.t), self.df_e)) * 2    # coef. p-values

self.R2 = 1 - self.e.var()/self.y.var()         # model R-squared
self.R2adj = 1-(1-self.R2)*((self.nobs-1)/(self.nobs-self.ncoef))   # adjusted R-square

self.F = (self.R2/self.df_r) / ((1-self.R2)/self.df_e)  # model F-statistic
self.Fpv = 1-stats.f.cdf(self.F, self.df_r, self.df_e)  # F-statistic p-value

def dw(self):
"""
Calculates the Durbin-Waston statistic
"""
de = diff(self.e,1)
dw = dot(de,de) / dot(self.e,self.e);

return dw

def omni(self):
"""
Omnibus test for normality
"""
return stats.normaltest(self.e) 

def JB(self):
"""
Calculate residual skewness, kurtosis, and do the JB test for normality
"""

# Calculate residual skewness and kurtosis
skew = stats.skew(self.e) 
kurtosis = 3 + stats.kurtosis(self.e) 

# Calculate the Jarque-Bera test for normality
JB = (self.nobs/6) * (square(skew) + (1/4)*square(kurtosis-3))
JBpv = 1-stats.chi2.cdf(JB,2);

return JB, JBpv, skew, kurtosis

def ll(self):
"""
Calculate model log-likelihood and two information criteria
"""

# Model log-likelihood, AIC, and BIC criterion values 
ll = -(self.nobs*1/2)*(1+log(2*pi)) - (self.nobs/2)*log(dot(self.e,self.e)/self.nobs)
aic = -2*ll/self.nobs + (2*self.ncoef/self.nobs)
bic = -2*ll/self.nobs + (self.ncoef*log(self.nobs))/self.nobs

return ll, aic, bic

def summary(self):
"""
Printing model output to screen
"""

# local time & date
t = time.localtime()

# extra stats
ll, aic, bic = self.ll()
JB, JBpv, skew, kurtosis = self.JB()
omni, omnipv = self.omni()

# printing output to screen
                                                                                         print                                                                                         '\n=============================================================================='
print "Dependent Variable: " + self.y_varnm
print "Method: Least Squares"
print "Date: ", time.strftime("%a, %d %b %Y",t)
print "Time: ", time.strftime("%H:%M:%S",t)
print '# obs:               %5.0f' % self.nobs
print '# variables:     %5.0f' % self.ncoef 
print '=============================================================================='
print 'variable     coefficient     std. Error      t-statistic     prob.'
print '=============================================================================='
for i in range(len(self.x_varnm)):
    print '''% -5s          % -5.6f     % -5.6f     % -5.6f     % -5.6f'''  %            tuple([self.x_varnm[i],self.b[i],self.se[i],self.t[i],self.p[i]]) 
print '=============================================================================='
print 'Models stats                         Residual stats'
print '=============================================================================='
print 'R-squared            % -5.6f         Durbin-Watson stat  % -5.6f' %              tuple([self.R2, self.dw()])
print 'Adjusted R-squared   % -5.6f         Omnibus stat        % -5.6f' % tuple([self.R2adj, omni])
print 'F-statistic          % -5.6f         Prob(Omnibus stat)  % -5.6f' % tuple([self.F, omnipv])
print 'Prob (F-statistic)   % -5.6f         JB stat             % -5.6f' % tuple([self.Fpv, JB])
print 'Log likelihood       % -5.6f         Prob(JB)            % -5.6f' % tuple([ll, JBpv])
print 'AIC criterion        % -5.6f         Skew                % -5.6f' % tuple([aic, skew])
print 'BIC criterion        % -5.6f         Kurtosis            % -5.6f' % tuple([bic, kurtosis])
print '=============================================================================='

if __name__ == '__main__':

##########################
### testing the ols class
##########################

# intercept is added, by default
m = ols(y,x1,y_varnm = 'y',x_varnm = ['x1','x2','x3'])
m.summary()
Can anyone help? Is this possible to do?

Thanks.

The Gnome fucked around with this message at 01:45 on Sep 18, 2011

tripwire
Nov 19, 2004

        ghost flow
No one is going to know how to help you unless you post the code.

The Gnome
Sep 8, 2011

by R. Guyovich
Sorry, forgot to include it. Post updated! Thanks.

tripwire
Nov 19, 2004

        ghost flow
All the indentation has been stripped. And that code looks atrocious.

With variable names like nobs, ncoef, df_e, df_r, the code is practically self documenting :D

The Gnome
Sep 8, 2011

by R. Guyovich

tripwire posted:

All the indentation has been stripped. And that code looks atrocious.

With variable names like nobs, ncoef, df_e, df_r, the code is practically self documenting :D

Would stackoverflow link help? http://stackoverflow.com/questions/7458391/python-mulilinear-regression-using-ols-code-with-specific-data

If that helps with the indentation, I'm not sure how to do that within SA? Sorry for the unorganized code.

No Safe Word
Feb 26, 2005

The Gnome posted:

Would stackoverflow link help? http://stackoverflow.com/questions/7458391/python-mulilinear-regression-using-ols-code-with-specific-data

If that helps with the indentation, I'm not sure how to do that within SA? Sorry for the unorganized code.

Your code indentation is hosed up on there too

vikingstrike
Sep 23, 2007

whats happening, captain
Why don't you just do the matrix algebra instead of using a class? Seems overkill. Make your x vectors a matrix and then multiply.

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

tripwire posted:

All the indentation has been stripped. And that code looks atrocious.

With variable names like nobs, ncoef, df_e, df_r, the code is practically self documenting :D

For some reason all of the scientific code I've ever seen is like this. It's awful.

crm
Oct 24, 2004

Haystack posted:

good info here

Ok, some more stuff since I dunno wtf

Python 2 or 3? (lol)

Are these frameworks / stacks something I can start up in debug mode and hot swap code and the like? I'm a big fan of not having to restart an app to see code changes.

jonypawks
Dec 1, 2003

"Why didn't you tell me you were the real Snake?" -- Ken

crm posted:

Ok, some more stuff since I dunno wtf

Python 2 or 3? (lol)

Are these frameworks / stacks something I can start up in debug mode and hot swap code and the like? I'm a big fan of not having to restart an app to see code changes.

Most if not all of the frameworks that have been recommended will use a development server that will have a debug option enabled by default. It'll usually display tracebacks right in the browser, and some will even let you drop into an interactive shell right there to help figure out the state of things. Pretty much every framework's development server will watch your app for changes and automatically restart when appropriate.

IMlemon
Dec 29, 2008
Hey,

I'm pretty new to Python so I'm trying to write a basic roguelike to familiarize myself to the language. I'm using libtcod library and I tried to write some unit tests but I'm running into some weird problems.

So I created this simple unit test that works when I put it directly into src folder:

code:
import unittest
import libtcodpy as libtcod


class Test(unittest.TestCase):

    def testName(self):
        assert(1 == 1);


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()
When I move it to tests package it stops working because it apparently cant resolve libtcod or something:

code:
Finding files... done.
Importing test modules ... Traceback (most recent call last):
  File "D:\dev\eclipse\plugins\org.python.pydev.debug_2.2.0.2011062419\pysrc\pydev_runfiles.py", line 307, in __get_module_from_str
    mod = __import__(modname)
  File "C:\Users\Almantas\Learning-Python\src\test.py", line 7, in <module>
    import libtcodpy as libtcod
  File "C:\Users\Almantas\Learning-Python\src\libtcodpy.py", line 41, in <module>
    _lib = ctypes.cdll['./libtcod-mingw.dll']
  File "C:\Python27\lib\ctypes\__init__.py", line 428, in __getitem__
    return getattr(self, name)
  File "C:\Python27\lib\ctypes\__init__.py", line 423, in __getattr__
    dll = self._dlltype(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
ERROR: Module: test could not be imported (file: C:\Users\Almantas\Learning-Python\src\tests\test.py).
done.
The weird thing is, libtcod resolves just fine when I'm using it in the actual code in other packages, so I'm kind of stumped as how I can fix it. Here's the project structure:

Adbot
ADBOT LOVES YOU

The Gnome
Sep 8, 2011

by R. Guyovich
Alright, I'm working with ols.py from scipy.org. When I input my own variables and try to initiate a multilinear regression, I'm getting an error.

Every time I try to put my variables in place of the random variables that came with ols.py, it gives me an error.

http://pastebin.com/PGZvEUWn

The error is found on this line:

code:
m = ols(y, x, y_varnm = 'y',x_varnm = ['x1','x2','x3'])
The error is:

code:
TypeError: this constructor takes no arguments
Thanks for the help!

  • Locked thread