से अधिक हो गई है, मेरे पास निम्न रिकर्सन कोड है, प्रत्येक नोड पर मैं एसक्यूएल क्वेरी को कॉल करता हूं ताकि नोड्स पैरेंट नोड से संबंधित हो सकें।पायथन: अधिकतम रिकर्सन गहराई
Exception RuntimeError: 'maximum recursion depth exceeded' in <bound method DictCursor.__del__ of <MySQLdb.cursors.DictCursor object at 0x879768c>> ignored
RuntimeError: maximum recursion depth exceeded while calling a Python object
Exception AttributeError: "'DictCursor' object has no attribute 'connection'" in <bound method DictCursor.__del__ of <MySQLdb.cursors.DictCursor object at 0x879776c>> ignored
विधि है कि मैं एसक्यूएल परिणाम प्राप्त करने के लिए कॉल:
def returnCategoryQuery(query, variables={}):
cursor = db.cursor(cursors.DictCursor);
catResults = [];
try:
cursor.execute(query, variables);
for categoryRow in cursor.fetchall():
catResults.append(categoryRow['cl_to']);
return catResults;
except Exception, e:
traceback.print_exc();
मैं वास्तव में उपरोक्त विधि से संबंधित कोई समस्या नहीं है, लेकिन मैं यह करने के लिए वैसे भी डाल
यहाँ त्रुटि है प्रश्न का उचित अवलोकन दें।
Recursion कोड:
def leaves(first, path=[]):
if first:
for elem in first:
if elem.lower() != 'someString'.lower():
if elem not in path:
queryVariable = {'title': elem}
for sublist in leaves(returnCategoryQuery(categoryQuery, variables=queryVariable)):
path.append(sublist)
yield sublist
yield elem
पुनरावर्ती क्रिया
for key, value in idTitleDictionary.iteritems():
for startCategory in value[0]:
print startCategory + " ==== Start Category";
categoryResults = [];
try:
categoryRow = "";
baseCategoryTree[startCategory] = [];
#print categoryQuery % {'title': startCategory};
cursor.execute(categoryQuery, {'title': startCategory});
done = False;
while not done:
categoryRow = cursor.fetchone();
if not categoryRow:
done = True;
continue;
rowValue = categoryRow['cl_to'];
categoryResults.append(rowValue);
except Exception, e:
traceback.print_exc();
try:
print "Printing depth " + str(depth);
baseCategoryTree[startCategory].append(leaves(categoryResults))
except Exception, e:
traceback.print_exc();
कोड कॉलिंग शब्दकोश मुद्रित करने के लिए,
print "---Printing-------"
for key, value in baseCategoryTree.iteritems():
print key,
for elem in value[0]:
print elem + ',';
raw_input("Press Enter to continue...")
print
तो प्रत्यावर्तन भी है गहरी मैं त्रुटि हो रही किया जाना चाहिए जब मैं अपना रिकर्सन फ़ंक्शन कॉल करता हूं, लेकिन जब मैं शब्दकोश प्रिंट करता हूं तो मुझे यह त्रुटि मिलती है।
इसे पुनरावर्ती रूप से इसके बजाय पुन: लिखें। –
'अगर पहले:' जांच पहले 'elem के लिए' के साथ अनावश्यक है: '। यदि क्वेरी एक खाली परिणाम सूची लौटाती है, तो इसके ऊपर फिर से चलना, वैसे ही कुछ भी नहीं करेगा, जैसा आप चाहें। साथ ही, आप सूची सूची के साथ अधिक आसानी से उस सूची को बना सकते हैं (और उन अर्धविराम अनावश्यक हैं और आम तौर पर बदसूरत माना जाता है :)) –
@KarlKnechtel अर्धविरामों के बारे में खेद है, क्या आप बता सकते हैं कि मैं सिर्फ पायथन प्रोग्रामिंग में शामिल हूं .... :) –