是否有任何可以自動查詢XML文件和/或RDBMS表的Python類似於LINQ的項目?該語法不一定非常像C#中的LINQ,但希望以pythonic的方式關閉。LINQ in Python
回答
如果你正在尋找一個ORM再有就是SQLAlchemy
Pynq實現表達式樹:
http://wiki.github.com/heynemann/pynq
微軟創建使用表達式樹的LINQ(語言集成查詢),這是一種關於如何將操作解析到樹中的數學概念,以便您可以獨立於結果分析操作。
Pynq是表達式樹理論和一些提供者的Python實現。逐漸會有更多的提供商,但Pynq將努力使自己的提供商儘可能地容易編寫。
聲音很酷。 8年未觸及。 – Robino 2017-03-15 11:14:51
你可能想看看kalamar:http://dyko.org/api/kalamar.html
它是利用語法或多或少類似於LINQ訪問存儲在不同格式數據的統一數據訪問庫(XML,MP3,...)上異構後端(文件,sql,...)。
我還沒有使用它,但是這表明承諾:
asq是一個簡單的實施Python中的LINQ風格的API,它工作在Python的iterables,包括在以下方面實現並行版本的Python標準庫多處理模塊。 API體育功能與對象的LINQ等同,100%聲明測試覆蓋率和comprehensive documentation。
2012年在Google Code上打開了一個問題,2015年7月遷移到GH,未於2017年7月解決https://github.com/sixty-north/asq/issues/5 – scls 2017-07-01 21:21:27
@scls rob-smallshire爲您提供了答案並關閉了問題 – 2017-09-07 16:59:38
我覺得Pony ORM應該在這裏提到。對我來說,這是 LINQ:
q = select((p.name, p.price) for p in Product)
q2 = q.filter(lambda n, p: n.name.startswith(「A」) and p > 100)
或直接從他們的着陸頁:
select(c for c in Customer
if sum(c.orders.price) > 1000)
如果您正在尋找跨語言的LINQ,它的發生地點是在Reactive Extensions其中微軟正在實施Python,Ruby,JavaScript等。這需要LINQ,所以他們通常最終會首先執行LINQ運算符;)
- 官方Python版本是在這裏:https://rxpy.codeplex.com/
- 但這裏還有另外一個端口:http://akuendig.github.io/RxPython/
只是爲了好玩我創建了以下代碼。
"""This module provides linq-like extensions for some common data structures"""
import __builtin__
class extlist(list):
"""subclass of list"""
def where(self, condition):
return extlist(filter(condition, self))
def aggregate(self, condition):
return extlist(reduce(condition, self))
def select(self, condition=lambda x: x):
return extlist(map(condition, self))
__builtin__.list = extlist
class extstr(str):
"""subclass of str"""
def where(self, condition):
return extstr(filter(condition, self))
def aggregate(self, condition):
return extstr(reduce(condition, self))
def select(self, condition=lambda x: x):
return extstr(map(condition, self))
__builtin__.str = extstr
使用
a = list('apple')
a.where(lambda u: u == 'p').select(lambda x: x.upper())
[ 'P', 'P']
我們推出PythonQL,這基本上是LINQ的Python類固醇(好吧,也許維生素)。它是Python語法的擴展,但是(drumrolls)你可以通過pip來安裝它,它不會破壞任何現有的代碼:)檢查出來:www.pythonql.org
- 1. LINQ to SQL in and not in
- 2. LINQ SingleOrDefault in Typescript
- 3. LINQ-to-SQL IN()
- 4. Linq IN Operator
- 5. Linq Index in Include
- 6. Foreach in Linq
- 7. Signin in Linq to Sql?
- 8. linq in或包含?
- 9. String.Replace in LINQ to Entities
- 10. LINQ「not in」not working
- 11. LINQ to SQL WHERE「IN」
- 12. SelectMany in Linq to entity
- 13. OrderBy in LINQ to Entity
- 14. LINQ的。載或IN
- 15. Linq SelectMany in Entity Framework
- 16. Vector3 in Meep in Python
- 17. Linq查詢中的'IN'和'NOT IN'
- 18. BFS in python from preorder and in
- 19. python in applescript:subprocess.call vs os.system in automator
- 20. Linq/C#orderby in web api
- 21. group by select max in linq
- 22. StartsWith string.empty in linq查詢
- 23. var in linq的使用
- 24. C#Linq Assign Anonymous Type in GroupBy
- 25. 如何使用Linq「NOT IN」
- 26. LINQ - SELECT DISTINCT與NOT IN
- 27. 'Random'Orderby in webservice using LINQ To Entities
- 28. 「Where In」with linq to sql
- 29. LINQ查詢WHERE IN clasue
- 30. 多對多LINQ「IN」查詢
請注意,有[pyquery](http:// pypi .python.org/pypi/pyquery),一個像Python一樣的jquery-syntax /功能包。 – user712092 2011-08-30 16:27:45
py-enumerable/py_linq https://github.com/viralogic/py-enumerable可以幫助 – scls 2017-07-01 21:16:44