본문 바로가기

파이썬2271

파이썬 Python 2.5.4-ImportError : etree.ElementTree라는 모듈이 없습니다. Windows에서 Python 2.5.4를 실행 중이며 ElementTree 또는 cElementTree 모듈을 가져 오려고 할 때 계속 오류가 발생합니다. 코드는 매우 간단합니다 (튜토리얼을 따르고 있습니다). import xml.etree.ElementTree as xml root = xml.Element('root') child = xml.Element('child') root.append(child) child.attrib['name'] = "Charlie" file = open("test.xml", 'w') xml.ElementTree(root).write(file) file.close() cmd에서 실행하거나 Python 인터프리터에서 직접 시도하면 오류 메시지가 표시되지 않습니다. Trace.. 2020. 11. 23.
파이썬 Python으로 소리 재생 Python에서 사운드 파일 (.wav)을 재생하는 가장 쉬운 방법은 무엇입니까? 가장 쉬운 것은 대부분의 플랫폼 독립적이고 최소한의 종속성을 요구한다는 것을 의미합니다. pygame은 확실히 옵션이지만 소리에 지나친 것처럼 보입니다. 해결 방법 s = Sound() s.read('sound.wav') s.play() 참조 페이지 https://stackoverflow.com/questions/307305 2020. 11. 23.
파이썬 Python Nose Import Error 다음은 패키지 파일 구조입니다. ./__init__.py ./foo.py ./tests ./__init__.py ./test_foo.py foo.py에는 다음이 포함됩니다. def dumb_true(): return True tests / test_foo.py에는 다음이 포함됩니다. import foo def test_foo(): assert foo.dumb_true() 두 init .py 파일이 비어 있습니다. 주 디렉토리 (foo.py가있는 곳)에서 nosetests -vv 를 실행하면 다음과 같은 결과가 나타납니다. Failure: ImportError (No module named foo) ... ERROR ==================================================.. 2020. 11. 23.
파이썬 How to filter objects for count annotation in Django? 간단한 Django 모델 Event 및 Participant 를 고려하십시오. class Event(models.Model): title = models.CharField(max_length=100) class Participant(models.Model): event = models.ForeignKey(Event, db_index=True) is_paid = models.BooleanField(default=False, db_index=True) 총 참가자 수로 이벤트 쿼리에 쉽게 주석을 달 수 있습니다. events = Event.objects.all().annotate(participants=models.Count('participant')) is_paid = True 로 필터링 된 참가자 수를 주.. 2020. 11. 22.
파이썬 Python을 사용하여 HTML에서 href 링크를 얻으려면 어떻게해야합니까? import urllib2 website = "WEBSITE" openwebsite = urllib2.urlopen(website) html = getwebsite.read() print html 여태까지는 그런대로 잘됐다. 하지만 일반 텍스트 HTML의 href 링크 만 원합니다. 이 문제를 어떻게 해결할 수 있습니까? 해결 방법 from BeautifulSoup import BeautifulSoup import urllib2 import re html_page = urllib2.urlopen("http://www.yourwebsite.com") soup = BeautifulSoup(html_page) for link in soup.findAll('a'): print link.get('href') ht.. 2020. 11. 22.
파이썬 Apache Spark 사전 빌드 버전에서 spark-csv와 같은 새 라이브러리를 추가하는 방법 bin/spark-shell --packages com.databricks:spark-csv_2.10:1.0.3 오류 가져 오기 >>> df_cat.save("k.csv","com.databricks.spark.csv") Traceback (most recent call last): File "", line 1, in File "/Users/abhishekchoudhary/bigdata/cdh5.2.0/spark-1.3.1/python/pyspark/sql/dataframe.py", line 209, in save self._jdf.save(source, jmode, joptions) File "/Users/abhishekchoudhary/bigdata/cdh5.2.0/spark-1.3.1/python/.. 2020. 11. 22.
파이썬 팬더의 가져 오기 오류를 해결하는 방법은 무엇입니까? python 2.7.7과 함께 Anaconda를 설치했습니다. 하지만 "import pandas"를 실행할 때마다 다음 오류가 발생합니다. "ImportError : C extension : y not built. C 확장을 먼저 빌드하려면 'python setup.py build_ext --inplace'를 실행해야 할 수 있습니다. " 제안 된 명령을 실행 해 보았지만 skipping 'pandas\index.c' Cython extension (up-to-date) skipping 'pandas\src\period.c' Cython extension (up-to-date) skipping 'pandas\algos.c' Cython extension (up-to-date) skipping 'panda.. 2020. 11. 22.
파이썬 Spark 컨텍스트 'sc'가 정의되지 않았습니다. 저는 Spark를 처음 사용하며 아래 사이트를 참조하여 PySpark를 설치하려고합니다. 미리 빌드 된 패키지와 SBT를 통해 Spark 패키지를 빌드하여 설치하려고했습니다. IPython Notebook에서 Python 코드를 실행하려고하면 아래 오류가 발생합니다. NameError Traceback (most recent call last) in () 1 # Check that Spark is working ----> 2 largeRange = sc.parallelize(xrange(100000)) 3 reduceTest = largeRange.reduce(lambda a, b: a + b) 4 filterReduceTest = largeRange.filter(lambda x: x % 7 == 0)... 2020. 11. 22.
파이썬 내 plt.savefig가 작동하지 않는 이유는 무엇입니까? 다음과 같이 간단한 파이썬 코드가 있습니다. import numpy as np import matplotlib.pyplot as plt """ Here are the solutions and the plot. """ # Create the axis and plot. plt.axis([0, 10, 0, 10]) axis_x = range(1, 11) grd = [1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1] grd2 = [1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2, 9.2, 10.2] plt.plot(axis_x, grd, '-g', label='BR1') plt.plot(axis_x, grd2, '-b', label='BR2') pl.. 2020. 11. 22.
파이썬 request.get () 사용시 제공된 스키마 및 기타 오류가 없습니다. 버전 2.7 및 Mac입니다. 어떤 이유로 "제공된 스키마 없음"과 같은 오류와 request.get () 자체를 사용할 때 오류가 발생합니다. 내 코드는 다음과 같습니다. # Saves the XKCD comic page for offline read import requests, os, bs4, shutil url = 'http://xkcd.com/' if os.path.isdir('xkcd') == True: # If xkcd folder already exists shutil.rmtree('xkcd') # delete it else: # otherwise os.makedirs('xkcd') # Creates xkcd foulder. while not url.endswith('#'): # If th.. 2020. 11. 22.