小编Tom*_*mmo的帖子

Python:正则表达式匹配字母数字不起作用?

我希望匹配从网站输入的字符串,以检查是否是字母数字,可能包含下划线.我的代码:

if re.match('[a-zA-Z0-9_]',playerName):
            # do stuff
Run Code Online (Sandbox Code Playgroud)

出于某种原因,这与疯狂的角色相匹配,例如:nIg○▲☆★◇◆

我只想要常规AZ和0-9和_匹配,这里有什么我想念的吗?

python regex

26
推荐指数
2
解决办法
5万
查看次数

Python PIL:如何在图像中间绘制椭圆?

我似乎在使这段代码工作时遇到了一些麻烦:

import Image, ImageDraw

im = Image.open("1.jpg")

draw = ImageDraw.Draw(im)
draw.ellipse((60, 60, 40, 40), fill=128)
del draw 

im.save('output.png')
im.show()
Run Code Online (Sandbox Code Playgroud)

这应该在(60,60)绘制一个40 x 40像素的椭圆.图像什么都不返回.

这段代码工作正常:

draw.ellipse ((0,0,40,40), fill=128)
Run Code Online (Sandbox Code Playgroud)

看起来,当我改变前2个坐标(椭圆应该放置的位置)时,如果它们大于要绘制的椭圆的大小,它将不起作用.例如:

draw.ellipse ((5,5,15,15), fill=128)
Run Code Online (Sandbox Code Playgroud)

可以工作,但只显示部分矩形.而

draw.ellipse ((5,5,3,3), fill=128)
Run Code Online (Sandbox Code Playgroud)

什么也没显示.

绘制矩形时也会发生这种情况.

python ellipse python-imaging-library

10
推荐指数
1
解决办法
3万
查看次数

Python:用urllib2处理Javascript?

我正在编写一个HTML scraper,它从网站上的表中获取值.我还需要获取图像的URL,但问题是这个图像是通过javascript动态生成的 - 当我通过urllib获取网站的内容时,Javascript不会在生成的HTML中运行或显示.

有没有办法让Javascript在通过urllib访问的页面上运行?

javascript python urllib2

5
推荐指数
1
解决办法
5036
查看次数

MySQL中大字符串的最佳数据类型

目前我将其设置为varchar,最大长度为15000 - 它存储论坛帖子,因此它们的大小可能会有很大差异.谢谢!

mysql

3
推荐指数
1
解决办法
7430
查看次数

Python:在B类中调用A类的方法A?

有许多类似的问题,但没有一个答案出现在现场 - 所以请耐心等待.

我正在努力学习使用Python的OOP,但我一直遇到错误(比如这个),这让我觉得这一切都没有意义,只是使用方法会更容易.

这是我的代码:

class TheGUI(wx.Frame):
    def __init__(self, title, size):
        wx.Frame.__init__(self, None, 1, title, size=size)

        # The GUI is made ...

        textbox.TextCtrl(panel1, 1, pos=(67,7), size=(150, 20))
        button1.Bind(wx.EVT_BUTTON, self.button1Click)

        self.Show(True) 

    def button1Click(self, event):
        #It needs to do the LoadThread function!

class WebParser:

    def LoadThread(self, thread_id):
        #It needs to get the contents of textbox!


TheGUI = TheGUI("Text RPG", (500,500))
TheParser = WebParser

TheApp.MainLoop()
Run Code Online (Sandbox Code Playgroud)

所以我遇到的问题是GUI类需要使用WebParser类中的函数,而WebParser类需要从GUI类中存在的文本框中获取文本.

我知道我可以通过将对象作为参数传递来做到这一点,但这似乎完全没有意义,必须有一种更合乎逻辑的方法来做到这一点,不使用类似乎毫无意义?

提前致谢!

python oop wxpython class

2
推荐指数
1
解决办法
1929
查看次数

Python:正则表达式...不工作?

我有这个代码:

    # If the username isn't alpha-numerics (inc: _, -, ., )
    if re.match('^[a-zA-Z0-9 _\-\.]+$', repName) == False:
        print 'DECLINE: '+repName
    else:
        print 'ACCEPTED: '+repName
Run Code Online (Sandbox Code Playgroud)

当我对这个字符串进行测试时:ɢᴀꜱᴛяɪᴄ(从网站上抓取)我得到了这个:

接受:É¢á'€œœ±á'>Ñ?ɪá'"

为什么要通过?另外为什么Python似乎改变了字符串?

python regex

0
推荐指数
1
解决办法
186
查看次数

PHP从父类CLOSED访问变量

我已经看到几个问题与真正相似的标题,但它们与我的具体问题无关.

基本上,我想在扩展核心的类中从我的核心类访问变量,但与其他示例相比,事情似乎相当复杂.我正在使用MVC框架.我已经简化了下面的代码来删除任何不相关的内容.

的index.php

// Load the core
include_once('core.php');
$core = new Core($uri, $curpath);
$core->loadController('property');
Run Code Online (Sandbox Code Playgroud)

core.php中

class Core
{
    public $uri;
    public $curpath;

    function __construct($uri, $curpath)
    {       
        $this->uri = $uri;
        $this->curpath = $curpath;
    }


    // Load the controller based on the URL
    function loadController($name)
    {       
        //Instantiate the controller
        require_once('controller/'.$name.'.php');
        $controller = new $name();
    }


}
Run Code Online (Sandbox Code Playgroud)

property.php

class Property extends Core
{
    function __construct()
    {
        print $this->curpath;
    }   
}
Run Code Online (Sandbox Code Playgroud)

打印$ this-> curpath只返回任何内容.变量已设置但为空.如果我在core.php中打印$ this-> curpath就打印好了.

我该如何访问这个变量?

php oop class

0
推荐指数
1
解决办法
1216
查看次数