第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 python 中提取正式的 java 方法參數(shù)并將它們添加到字符串列表中?

如何在 python 中提取正式的 java 方法參數(shù)并將它們添加到字符串列表中?

回首憶惘然 2022-12-15 10:59:10
我有一個(gè) java 方法,我需要從方法聲明中傳遞給這個(gè)方法的參數(shù)。下面的代碼給出了應(yīng)該提取方法聲明但輸出None我希望將提取的參數(shù)添加到字符串列表中。import ref = open("source_code.txt", "r")source_code = f.read()match = re.match("(public|protected|private|static|\s) +[\w\<\>\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;])", source_code)print(match)我想要這樣的東西:輸入:/**    * Adds a subset of the edges of the specified source graph to the specified destination graph.    * The behavior of this operation is undefined if either of the graphs is modified while the    * operation is in progress. {@link #addEdgeWithVertices} is used for the transfer, so source    * vertexes will be added automatically to the target graph.    *    * @param destination the graph to which edges are to be added    * @param source the graph used as a source for edges to add    * @param edges the edges to be added    * @param <V> the graph vertex type    * @param <E> the graph edge type    *    * @return <tt>true</tt> if this graph changed as a result of the call    */public static <V, E> boolean addAllEdges(Graph<? super V, ? super E> destination, Graph<V, E> source, Collection<? extends E> edges)   {       boolean modified = false;       for (E e : edges) {           V s = source.getEdgeSource(e);           V t = source.getEdgeTarget(e);           destination.addVertex(s);           destination.addVertex(t);           modified |= destination.addEdge(s, t, e);       }       return modified;   }這從方法聲明中提取destination, source, :edgepublic static <V, E> boolean addAllEdges(Graph<? super V, ? super E> destination, Graph<V, E> source, Collection<? extends E> edges)輸出:extracted_arguments = ['destination', 'source', 'edge']
查看完整描述

1 回答

?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊

此外,您必須為此使用解析器

在這里找到方法 args 和 split

import re

match = re.search("(public|protected|private|static) .*\((.*)\)", source_code)

args=[i.split()[-1] for i in re.sub('<.*?>','',match[2]).split(',')]

print(args)


查看完整回答
反對(duì) 回復(fù) 2022-12-15
  • 1 回答
  • 0 關(guān)注
  • 82 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)