小编Kev*_*vin的帖子

将相同的字符串附加到Python中的字符串列表中

我试图获取一个字符串,并将其附加到列表中包含的每个字符串,然后有一个包含已完成字符串的新列表.例:

list = ['foo', 'fob', 'faz', 'funk']
string = 'bar'

*magic*

list2 = ['foobar', 'fobbar', 'fazbar', 'funkbar']
Run Code Online (Sandbox Code Playgroud)

我尝试了循环,尝试列表理解,但它是垃圾.一如往常,任何帮助,非常感谢.

python list

160
推荐指数
7
解决办法
15万
查看次数

django在ubuntu中安装的位置

我正在寻找django 的init .py文件.我尝试了whereis并找到了,但我得到了很多dirs.

python django ubuntu

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

从TextCtrl框中获取字符串

如何从TextCtrl盒子里拿出琴弦?这是练习代码:

import wx



class citPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)


        wx.StaticText(self, -1, "Choose put you would like:", (45, 15))

        self.quote = wx.StaticText(self, -1, "1:", wx.Point(275, 180), wx.Size(200, -1))
        self.quote = wx.StaticText(self, -1, "2:", wx.Point(275, 230), wx.Size(200, -1))
        self.quote = wx.StaticText(self, -1, "3:", wx.Point(275, 280), wx.Size(200, -1))




class nextButton(wx.Button):
    def __init__(self, parent, id, label, pos):
        wx.Button.__init__(self, parent, id, label, pos)

class cancelButton(wx.Button):
    def __init__(self, parent, id, label, pos):
        wx.Button.__init__(self, parent, id, label, pos)

class searchBox(wx.TextCtrl):
def __init__(self, …
Run Code Online (Sandbox Code Playgroud)

python wxpython textctrl

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

使用BeautifulSoup在HTML中搜索和替换

我想用BeautfulSoup搜索和替换<\a>使用<\a><br>.我知道如何打开urllib2然后解析以提取所有<a>标签.我想要做的是搜索并用结束标记和中断替换结束标记.任何帮助,非常感谢.

编辑

我认为它会类似于:

soup.findAll('a').
Run Code Online (Sandbox Code Playgroud)

在文档中,有一个:

find(text="ahh").replaceWith('Hooray')
Run Code Online (Sandbox Code Playgroud)

所以我认为这将是:

soup.findAll(tag = '</a>').replaceWith(tag = '</a><br>')
Run Code Online (Sandbox Code Playgroud)

但这不起作用,而python help()并没有给出多少

python beautifulsoup

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

尝试使用批处理文件在Windows中编辑注册表

我支持全国各地运行Windows XP的几个办事处.它们是独立的,没有Windows Server或Active Directory,类似的东西.我刚刚将它们切换到Google Apps,并在此过程中将Windows Live Messenger替换为Google Talk.我真的想阻止Windows Live被使用,该平台发送了大量垃圾邮件,似乎有很多漏洞.我已经测试过对密钥进行注册表编辑

HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun 
Run Code Online (Sandbox Code Playgroud)

添加字符串值msnmsgr.exe设置为1.我在一台机器上手动完成它,并且它在两个配置文件下工作,它不会启动Messenger.在我成功之后,我写了一个.REG文件:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun]
"msnmsgr.exe"="1"
Run Code Online (Sandbox Code Playgroud)

一个批处理文件,从同一目录运行,写成如下:

@ECHO off

REGEDIT.EXE /S msn.reg
Run Code Online (Sandbox Code Playgroud)

它似乎写入注册表,但Live正在启动.不知道发生了什么.似乎这可能是在Serverfault和这里之间的任何一种方式,但我去了这里,因为管理部分似乎已经解决,但涉及的小编程没有成功.

在此先感谢您的任何帮助.

windows registry batch-file

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

从XML python中检索数据

我试图遍历Google XML以检索大约6个字段.我使用Google提供的gdata为我的Google Apps域中的用户个人资料提取XML Feed.这是结果:

<?xml version="1.0"?>
-<ns0:feed ns1:etag="W/"LIESANDCRAPfyt7I2A9WhHERE."" xmlns:ns4="http://www.w3.org/2007/app" xmlns:ns3="http://schemas.google.com/contact/2008" xmlns:ns2="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:ns1="http://schemas.google.com/g/2005" xmlns:ns0="http://www.w3.org/2005/Atom">
    <ns0:updated>2012-01-25T14:52:12.867Z</ns0:updated>
    <ns0:category term="http://schemas.google.com/contact/2008#profile" scheme="http://schemas.google.com/g/2005#kind"/>
    <ns0:id>domain.com</ns0:id>
    <ns0:generator version="1.0" uri="http://www.google.com/m8/feeds">Contacts</ns0:generator>
    <ns0:author>
        <ns0:name>domain.com</ns0:name>
    </ns0:author>
    <ns0:link type="text/html" rel="alternate" href="http://www.google.com/"/>
    <ns0:link type="application/atom+xml" rel="http://schemas.google.com/g/2005#feed" href="https://www.google.com/m8/feeds/profiles/domain/domain.com/full"/>
    <ns0:link type="application/atom+xml" rel="http://schemas.google.com/g/2005#batch" href="https://www.google.com/m8/feeds/profiles/domain/domain.com/full/batch"/>
    <ns0:link type="application/atom+xml" rel="self" href="https://www.google.com/m8/feeds/profiles/domain/domain.com/full?max-results=300"/>
    <ns2:startIndex>1</ns2:startIndex>
    <ns2:itemsPerPage>300</ns2:itemsPerPage>
    <ns0:entry ns1:etag=""CRAPQR4KTit7I2A4"">
        <ns0:category term="http://schemas.google.com/contact/2008#profile" scheme="http://schemas.google.com/g/2005#kind"/>
        <ns0:id>http://www.google.com/m8/feeds/profiles/domain/domain.com/full/nperson</ns0:id>
        <ns1:name>
            <ns1:familyName>Person</ns1:familyName>
            <ns1:fullName>Name Person</ns1:fullName>
            <ns1:givenName>Name</ns1:givenName>
        </ns1:name>
        <ns0:updated>2012-01-25T14:52:13.081Z</ns0:updated>
        <ns1:organization rel="http://schemas.google.com/g/2005#work" primary="true">
            <ns1:orgTitle>JobField</ns1:orgTitle>
            <ns1:orgDepartment>DepartmentField</ns1:orgDepartment>
            <ns1:orgName>CompanyField</ns1:orgName>
        </ns1:organization>
        <ns3:status indexed="true"/>
        <ns0:title>Name Person</ns0:title>
        <ns0:link type="image/*" rel="http://schemas.google.com/contacts/2008/rel#photo" href="https://www.google.com/m8/feeds/photos/profile/domain.com/nperson"/>
        <ns0:link type="application/atom+xml" rel="self" href="https://www.google.com/m8/feeds/profiles/domain/domain.com/full/nperson"/>
        <ns0:link type="application/atom+xml" rel="edit" href="https://www.google.com/m8/feeds/profiles/domain/domain.com/full/nperson"/>
        <ns1:email rel="http://schemas.google.com/g/2005#other" …
Run Code Online (Sandbox Code Playgroud)

python xml

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

尝试使用BeautifulSoup从网页中获取绝对链接

我正在使用BeautifulSoup阅读网页的内容.我想要的只是抓住<a href>那个开始http://.我知道在beautifulsoup你可以搜索属性.我想我只是遇到语法问题.我想它会有类似的东西.

page = urllib2.urlopen("http://www.linkpages.com")
soup = BeautifulSoup(page)
for link in soup.findAll('a'):
    if link['href'].startswith('http://'):
        print links 
Run Code Online (Sandbox Code Playgroud)

但那回归:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Python26\lib\BeautifulSoup.py", line 598, in __getitem__
    return self._getAttrMap()[key]
KeyError: 'href'
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?提前致谢.

编辑 这不适用于任何网站.该脚本从用户获取URL.所以内部链接目标将是一个问题,这也是我只想<'a'>从页面中获取的原因.如果我转向它www.reddit.com,它解析开始的链接,它得到这个:

<a href="http://www.reddit.com/top/">top</a>
<a href="http://www.reddit.com/saved/">saved</a>
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Python26\lib\BeautifulSoup.py", line 598, in __getitem__
    return self._getAttrMap()[key]
KeyError: 'href'
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup

4
推荐指数
1
解决办法
2972
查看次数

Django教程 - 在/ polls /上的TemplateDoesNotExist

我试图让这个工作一百万次.我已经独自放了一个星期然后回来了.我用谷歌搜索并阅读了与此有关的每篇文章.在没有找到答案的情况下,我让不安全的傻瓜在消息组中贬低.我只想让它发挥作用.当我在Django教程的第三部分中进行操作时,我将进入为索引页面制作模板的部分,当我在浏览器中进行检查时,它会出现TemplateDoesNotExist at /polls/.我已签文件的所有权,移动它周围的一切,总是在不断变化的TEMPLATES_DIRsetting.py.我已将文件的内容传递给cat以确保其正常工作.为了让这个工作起来,我为奇怪的上帝牺牲了动物.我现在转向你.我确信这是最愚蠢的事情,我对此毫无疑问.我只是想让它发挥作用.

我不确定你想要/需要的代码/回溯的哪些部分,让我知道我会发布它们.我在Ubuntu 10.10上这样做

编辑

来自settings.py:

TEMPLATE_DIRS = (
    "home/kevin/first/tutorial/temps"
)
Run Code Online (Sandbox Code Playgroud)

这曾经住过〜,但我搬进了项目文件夹,认为这会有所帮助.

结构(省略所有编译的python文件):

~/first/tutorial/:
__init__.py,
manage.py,
polls,
settings.py,
temps,
tut.db,
urls.py

temps:
index.html

polls:
admin.py,
__init__.py,
models.py,
tests.py,
views.py,
Run Code Online (Sandbox Code Playgroud)

python django

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

如何在Windows上启动python脚本?

我已经运行了一些使用批处理作业,但是,我想知道什么是最合适的?也许使用time.strftime?

python

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

WxPython,Windows Vista 64位和失败

我有Windows Vista 64位SP2.我正在尝试使用wxPython与Python进行GUI开发,因为我所有的研究都指出了这种方式.我已经下载并安装了win64 wxPython.我每次都得到同样的错误.

Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.

>>> import wx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4
5, in <module>
    from wx._core import *
  File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i
n <module>
    import _core_
ImportError: DLL load failed: %1 is not a valid Win32 application.
Run Code Online (Sandbox Code Playgroud)

我在我的python上安装了c,我在c:\ program files(x86)中安装了python26并在那里安装了wxPython,我使用的是32bit,64bit.我试过到处寻找类似的问题,我几乎没有见过其他人这个问题.任何帮助将不胜感激.

python 64-bit wxpython windows-vista

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